Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Server reconnecting to client on connection loss

$
0
0
I have 2 questions

1.My server code can connect to the android client only once and if the connection is lost it does not reconnect and therefore it is lost forever

This is my code

#include <GUIConstants.au3>
Run("C:\Program Files (x86)\Garmin\GTN Trainer Lite\GTN\sys\sim\GTN Simulator.exe")
WinWaitActive("GTN Trainer Lite")
WinMove("GTN Trainer Lite", "", 500, 150, 550, 550)
Send("!p")
Sleep(10000)
MouseClick("left", 760, 600, 10)
Sleep(2000)
MouseClick("left", 760, 600, 10)
Sleep(2000)
MouseClick("left", 750, 595, 10)
Sleep(5000)
$ServerIP = @IPAddress1
$Port = 5000
TCPStartup()
$MainSocket = TCPListen($ServerIP, $Port)
If $MainSocket = -1 Then Exit
$ConnectedSocket = -1
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
TrayTip("Info", "Connected", 2)
While 1
$recv = TCPRecv($ConnectedSocket, 100000)
;If @error Then ExitLoop
If $recv <> "" Then
	 TrayTip("Incoming Command", $recv, 5)
	 _CommandToAction($recv)
EndIf
;~	 ;If $recv = 3 Then Exit
WEnd
TrayTip("info", "Closing socket", 5)
TCPCloseSocket($ConnectedSocket)
TrayTip("info", "TCP shutdown", 5)
TCPShutdown()
Exit
Func _CommandToAction($command)
If StringInStr($command, "left") Then
	 TrayTip("info", $command, 5)
	 MouseClick("left", 990, 620,1, 10)
EndIf
If StringInStr($command, "right") Then
	 TrayTip("info", $command, 5)
	 MouseClick("left", 1010, 620,1, 10)
EndIf
EndFunc ;==>_CommandToAction





How do I modify the program to reconnect to the client even on loss of connection?

2. The received data from the client has a new line character, how do i remove it? I tried using
stringReplace($command,@CRLF,"")
but it doesn't work

Any help is appreciated. Very new to AutoIt and to this forum

Any help please?

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>