pingpong24 Posted December 31, 2005 Share Posted December 31, 2005 Hi, my script doesnt work and i cant figure out how to fix the problem. a client program is sending a STRING via port 6969 through the established socket. client ----> my server. what happens is, i tried $x=TCPRecv(mysocket) but $x is always blank, and i tired various things but i can never get the $x... to contain the data sent by the client. so here it again what i want to do: send a string from the client to the server.. i know the string is sent from the client correctly as other programs can easily get what the client is sending. however my script returns 1-1-1-1-1-1-1-1-1-1 :S. thanks #include <File.au3> Global $MainSocket Local $MaxLength = 600; Maximum Length Of Text Local $Port = 6969; Port Number Local $Server = @IPAddress1; Server IpAddress Dim $accept = -1 Dim $Data = -1 TCPStartup() $MainSocket = TCPlisten($Server, $Port) If $MainSocket = -1 Then MsgBox(16, "Error", "Unable to connect.") Exit EndIf While 1 $accept = TCPAccept($MainSocket) If $accept >= 0 Then $Data = TCPRecv($MainSocket, $MaxLength) MsgBox(0,"","server and client connected",1) ExitLoop EndIf FileWrite("somebs.txt", $Data) WEnd Func OnAutoItExit() TCPCloseSocket($MainSocket) TCPShutdown() EndFunc ;==>OnAutoItExit NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
pingpong24 Posted December 31, 2005 Author Share Posted December 31, 2005 I fixed it my self with the code below but though i dont understand why my other code didnt work, this below code was created via trail and error. #include <File.au3> Global $MainSocket Local $MaxLength = 600; Maximum Length Of Text Local $Port = 6969; Port Number Local $Server = @IPAddress1; Server IpAddress Dim $recivied ="" Dim $testa = "" TCPStartup() $MainSocket = TCPlisten($Server, $Port) If $MainSocket = -1 Then MsgBox(16, "Error", "Unable to connect.") Exit EndIf While 1 $testa = TCPAccept($MainSocket) If $testa >= 0 Then $recivied = TCPRecv($testa, $MaxLength) EndIf FileWrite("somebs.txt",$recivied) WEnd Func OnAutoItExit() TCPCloseSocket($MainSocket) TCPShutdown() EndFunc ;==>OnAutoItExit NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
erifash Posted December 31, 2005 Share Posted December 31, 2005 You should use TCPRecv() in a While...WEnd loop just in case the server/client doesn't respond quick enough. Use it like this:While 1 $testa = TCPAccept($MainSocket) If $testa >= 0 Then $recieved = "" While $recieved = "" $recivied = TCPRecv($testa, $MaxLength) WEnd FileWrite("somebs.txt", $recivied) EndIf WEndI hope I helped! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
pingpong24 Posted January 1, 2006 Author Share Posted January 1, 2006 yeah i understand that, the problem was with autoit helpfile it says TCPRecv gets its socket id from tcp listen, which is incorrect it should get it from TCP accept. mainsocket The main socket identifier (SocketID) as returned by a TCPListen function. ill report this as a bug NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
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