stigma Posted March 6, 2007 Share Posted March 6, 2007 Heya. I'm trying to create a basic server/client allowing for sending simple strings from one PC to another on a LAN and displaying them on the screen. The problem is that the server (recipient) seems to be getting lots and lots of empty strings "" from TCPrecv. The strange thing is that it isnt a total miscommunication, because every now and then, the message DOES actually go through! This makes it very hard to troubleshoot the problem wtih my limited experience. The code is very short, so im posting it here in hopes that someone can point out any basic mistakes. The server side code is supposed to check for new messages as often as possible, but not run continously. Server side: Dim $messageArray[10] TCPStartUp() $recieveSocket = TCPListen("192.168.1.104", 40100) if $recievesocket == -1 then msgbox(0,"ERROR","Error opening listen socket!") func RecieveMessage() $socket = TCPAccept($recieveSocket) if $socket <= 0 Then Return False Else $message = TCPRecv( $socket, 1024 ) ;~ while $message == "" ;~ UpdateTooltip("blank string!") ;~ $message = TCPRecv( $socket, 300 ) ;~ WEnd if $message == "" then msgbox(0,"ERROR","recieved a blank string from TCPrecv!") $messageArray = StringSplit($message,"|") Return True EndIf EndFunc while 1 UpdateTooltip(RecieveMessage()) if RecieveMessage() == True Then UpdateTooltip($messageArray[1]) UpdateTooltip($messageArray[2]) UpdateTooltip($messageArray[3]) UpdateTooltip($messageArray[4]) EndIf Sleep(1000) wend client side: TCPStartUp() $GaxxIP = "192.168.1.104" $GaxxPort = 40100 ;~ $GaxxRecieveSocket = TCPConnect("192.168.1.104",40100) $i=0 while 1 SendMessage("Hello??, anyone out there?|we come in peace!|honestly!|" & $i & "|end",$gaxxip,$gaxxport) ;~ Sleep(1000) $i = $i+1 wend func SendMessage($message,$ip,$port) $socket = TCPConnect($ip,$port) while $socket == -1 $socket = TCPConnect($ip,$port) WEnd TCPSend($socket,$message) Sleep(1000) EndFunc Any suggestions on what to try?... -Stigma Link to comment Share on other sites More sharing options...
stigma Posted March 6, 2007 Author Share Posted March 6, 2007 Oh, you've got to be kidding me... I just found out what was wrong (isn't that typical, you never find the error until JUST after you have posted for help?) If nothing else maybye someone can avoid the same newbie mistake. while 1 SendMessage("Hello??, anyone out there?|we come in peace!|honestly!|" & $i & "|end",$gaxxip,$gaxxport) ;~ Sleep(1000) $i = $i+1 wend Notice the sleep line is commented out eeermm... bad idea. spams the socket with probably thousands o requests a second. I guess a bit of randomness can be expected then =/ -Stigma 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