LuuQuangICT Posted August 26, 2016 Posted August 26, 2016 Hello every body! I am trying to dev an simple chat using TCP. but it don't work for me. Please help me. I want to in 1 second, Client will send to server a message. And then, Server recv this message and write to Console. But when i run server and client. In server, i was recv only one message. Please tell me why? In server, i code: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $r = @CRLF; Global $ip = "127.0.0.1" Global $port = 1337 Global $client, $iSocket TCPStartup() $iSocket = TCPListen($ip, $port) While 1 $client = TCPAccept($iSocket) If $client <> -1 Then TCPSend($client, "Client is Connected"); EndIf $msg = TCPRecv($client, 1024) if StringLen($msg) <>0 Then ConsoleWrite("Server recv: " &$msg) EndIf TCPSend($client, "Send this msg to client"); Sleep(1000) WEnd In client, i code: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $ip = "127.0.0.1" Global $port = 1337 Global $r = @CRLF; TCPStartup() $server = TCPConnect($ip, $port) While 1 TCPSend($server, "Send msg to server") Sleep(1000) WEnd
Developers Jos Posted August 26, 2016 Developers Posted August 26, 2016 Something like this?: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $r = @CRLF ; Global $ip = "127.0.0.1" Global $port = 1337 Global $client, $iSocket TCPStartup() $iSocket = TCPListen($ip, $port) While 1 $client = TCPAccept($iSocket) If $client <> -1 Then ;~ TCPSend($client, "Client is Connected"); ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : "Client is Connected >Error code: ' & @error & @CRLF) ;### Debug Console While 1 $msg = TCPRecv($client, 1024) If StringLen($msg) <> 0 Then ConsoleWrite("Server recv: " & $msg & @crlf) EndIf Sleep(10) WEnd EndIf WEnd Jos LuuQuangICT 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
LuuQuangICT Posted August 26, 2016 Author Posted August 26, 2016 Thank you so much! i was found on google but it don't work for me !!! Thank you once again
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