I'm trying to create two sides; A client side and a server side. I've got each one to work and send data from the client to the server, but if two clients are sending data at the same time. I would like to be able to get both and not just have one send while the other one gets ignored. Is there anyway I can implement a buffer so that when one connection gets done the other then starts receiving from the second client?
Here is my code.
~Client Side~
~Server Side~
Here is my code.
~Client Side~
[ autoit ]
TCPStartup() HotKeySet("{Esc}", "Quit") Local $ip, $port, $data, $connect $ip = "*servers IP address here*" $port = 21230 $connect = TCPConnect($ip, $port) If @error Then ConsoleWrite("Could not connect to " & $ip) sleep(1000) Quit() EndIf message() ;ConsoleWrite($data) Sleep(3000) Quit() Func message() Local $File, $Line = "", $i = 0, $EOF = "" $File = FileOpen("tcpexample.txt", 0) If $File = -1 Then MsgBox(0, "Error", "Unable to read the file.") Exit EndIf Do $Line = FileReadLine($File) $EOF = @error ConsoleWrite($Line & @CRLF) TCPSend($connect, $Line) If @error Then ConsoleWrite("There was an error sending." & @CRLF) EndIf sleep(500) Until $EOF = -1 FileClose($File) EndFunc Func Quit() TCPShutdown() Exit EndFunc
~Server Side~
[ autoit ]
TCPStartup() HotKeySet("{Esc}", "Quit") Local $ip, $port, $Accept, $Listen, $AcceptError = True, $Result $Result = FileOpen("tcptest.txt", 1) $ip = @IPAddress1;try $IPAddress2/3/4 if this doesn't work $port = 21230 $Listen = TCPListen($ip, $port) If ($listen = - 1 or $listen = 0) and (@error = 1 or @error = 2) Then ConsoleWrite("TCPListen returned @error: " & @error) Quit() EndIf While 1 If $AcceptError = True Then AcceptConnection() EndIf If $AcceptError = False Then $recv = "" $recv = TCPRecv($Accept, 1024) If @Error Then ConsoleWrite("Connection timed out: " & $Accept & @CRLF) $AcceptError = True EndIf If $recv <> "" Then FileWriteLine($Result, $recv) ConsoleWrite("We received this: " & $recv & @CRLF) EndIf EndIf WEnd Func Quit() TCPShutdown() FileClose($Result) Exit EndFunc Func AcceptConnection() $AcceptError = True While 1 $Accept = TCPAccept($Listen) If $Accept <> -1 Then ConsoleWrite($accept & " has connected" & @CRLF) $AcceptError = False ExitLoop EndIf WEnd EndFunc