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

TCP Client and Server

$
0
0
Hello

I have been training in TCP connections and with the help of some tutorials i have made a Client and a Server here are the Scripts:
Client:
[ autoit ]      
Tcpstartup() $Socket = TCPConnect(@IPAddress1, 403) If $Socket = -1 Then MsgBox(0, "Error", 'Could not conncet to the server') EndIf ;$SendBytes = TCPSend($Socket, 'Hello, client has made connection with the server') While 1 $Order = InputBox('Send Order', 'Type your order here:') $SendBytes = TCPSend($Socket, $Order) If $SendBytes = 0 Then MsgBox(0, 'Error', 'The packet was not able to reach the server') EndIf WEnd TCPCloseSocket($Socket) TCPShutdown()

Server:
[ autoit ]      
TCPStartup() $MainSocket = TCPListen(@IPAddress1, 403) While 1 $AcceptedSocket = TCPAccept($MainSocket) If $AcceptedSocket <> -1 Then $RecievedData = TCPRecv($AcceptedSocket, 1000000) If $RecievedData <> "" Then MsgBox(0, 'Data Recived', $RecievedData) TCPCloseSocket($AcceptedSocket) EndIf EndIf WEnd
I don't know why but the Client does not work i mean this does not work:
[ autoit ]      
$Order = InputBox('Send Order', 'Type your order here:') $SendBytes = TCPSend($Socket, $Order)
However if i delete this:
[ autoit ]      
While 1 $Order = InputBox('Send Order', 'Type your order here:') $SendBytes = TCPSend($Socket, $Order) If $SendBytes = 0 Then MsgBox(0, 'Error', 'The packet was not able to reach the server') EndIf WEnd
And insert this instead (Without comment mark of course), it works (sends the text):
[ autoit ]      
;$SendBytes = TCPSend($Socket, 'Hello, client has made connection with the server')

Anyone can help me?

Thanks

Viewing all articles
Browse latest Browse all 12506

Trending Articles



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