more TCP grief
BlitzPlus Forums/BlitzPlus Beginners Area/more TCP grief
| ||
Hi guys, I'm trying to write a simple TCP client app which recieves a message from a TCP server and displays it on screen. I can get it to work the other way round (client talking to server) but this won't work for what I need. Basically, I've got an RFID reader program which acts as a server, so all I need Blitz for is the client bit, but at the moment I'm trying to get the whole thing working in Blitz so I've made a makeshift server. All servers and clients are always on the same machine. Here's the code: ;server code timer = CreateTimer (1) svrGame=CreateTCPServer(50000) If svrGame<>0 Then Print "Server started successfully." Else End End If strmGame=OpenTCPStream("127.0.0.1",50000) While Not KeyHit(1) WriteLine strmGame,"testing" Print"sent" WaitTimer timer Wend End ;client code timer = CreateTimer(1) strmGame=OpenTCPStream("127.0.0.1",50000) If strmGame = 0 Then RuntimeError "couldnt open stream" While Not KeyDown (1) Print ReadLine$(strmGame) WaitTimer(timer) Wend End Basically, the server runs okay, and as far as I can tell sends the message (it prints "sent" over and over). The client is printing the contents of readline() each time, but the contents is an empty string. I've tried using readavail() to get the size of the incoming message and it's returning zero. Any ideas would be much appreciated, Neil |
| ||
Sorry cannot help you completely right now, as at work, but here is a link to a small TCP library I put together a while ago. (very simple) http://www.blitzbasic.com/codearcs/codearcs.php?code=2403#comments |
| ||
Thanks, Matty. I used your code to see if I could get it working, but the square on the client screen isn't moving. We do not understand enough about B+ to get it to work. We just need a bare minimum hack (i.e. no need for error checking, stability, user friendliness, or graphics) - only as much as the code as I posted above. All we need the client to do is open a stream to the correct port, repeatedly check for a string, and then print each string when it is received. The server just needs to send a random string every so often. Is what I posted anywhere near? Cheers neil |
| ||
Error in server.. strmGame=OpenTCPStream("127.0.0.1",50000) shold be strmGame = Accepttcpstream(svrGame) |
| ||
Corrected Server Code ClientCode |