jwka Posted November 9, 2011 Posted November 9, 2011 Hi, I have scanned around but not so successful yet in serch of mentionned script. I nned to establish a more complex "handshaked" communication: - send "command" - receive result (text, multiple bytes up to a couple of hundreds) - send "ack" - receive "ready" and start over again. Seems I need a listenner AND a sender. But I have no glue how to do it. Can anyone help with a small example? Thanks so much in advance! jwka
gononono64 Posted November 10, 2011 Posted November 10, 2011 Client: Global $Connected2 $IP = "5.59.4.36" $Port =65432 $MyIP = @IPAddress1 ;Start TCP services TCPStartup() ;Connecting to main socket $ConnectedSocket = TCPConnect($IP, $Port) MsgBox(0,"",$ConnectedSocket) If @error Then MsgBox(4096, "Error ", "TCPConnect error: " & @error) EndIf ;Send info TCPSend($ConnectedSocket, $MyIP) ; Create a Listening "SOCKET" $MainSocket2 = TCPListen($MyIP, $Port) If @error Then MsgBox(4096, "Error ", "TCPListen error: " & @error) Exit EndIf While 1 $Connected2 = TCPAccept( $MainSocket2) ; look for client connection $recv = TCPRecv($Connected2, 10000000) If Not @error Then Endit() WEnd Func Endit() MsgBox(0,"connected",$recv) TCPCloseSocket($ConnectedSocket) sleep(300) TCPCloseSocket($Connected2) TCPShutdown ( ) exit EndFunc Server: global $connectedsocket $ip = @IPAddress1 MsgBox(0,"",@IPAddress1) $port = 65432 ;to start tcp services TCPStartup() ;create listening socket $mainsocket = TCPListen($ip, $port) If $mainsocket = -1 Then Exit ;Accept incoming clients and recieve info While 1 $connectedsocket = TCPAccept($mainsocket) If $ConnectedSocket >= 0 Then $ip2 = TCPRecv($connectedsocket,1000000) ;create new socket to send connected message $socket2 = TCPConnect($ip2, $port) TCPSend($socket2, "connected") EndIf WEnd TCPCloseSocket($connectedsocket) TCPCloseSocket($socket2) TCPShutdown()
lgvlgv Posted November 10, 2011 Posted November 10, 2011 i use running 1 server that speaks with 50+ clients, works fantastic and is so easy to use, examples are in the html doc. (planning to use it on 200+ clients)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now