Problem with TCP

Blitz3D Forums/Blitz3D Beginners Area/Problem with TCP

Robert M Jolly(Posted 2006) [#1]
Ok, I have a problem with the TCP commands. Please assume that i know nothing about TCP because i know nothing :-). I have been working on this for hours and still no luck.

The program is simple. One application that is a server and the other that is a client. I run the server app (the code will be listed below) and then i run the client app. I use the WriteString function to write a line to the server. It works! Then directly underneath the first writeline i put another write line (it can even be the same exact statement) and it will not send it to the server. I have no clue why. Here is the code.

;This is the server program for our game

;Create the TCP server
	svr1 = CreateTCPServer (8767)
;Check to see if the server started or not.  If not keep retrying 	
	Repeat 
		
		If KeyDown(1) Then
			End 
		End If
		
		If svr1 <> 0
			Print "The server started."
		Else
			Print "The server failed to start."
			Print "Press any key to retry."
			WaitKey
		End If
	Until svr1 <> 0 
	

;Now that the server started tell the server started tell the user that he or she is
;going into the main program to accept TCP streams.
	Print "Now Accepting TCP Streams."
	Print "The Information will appear when the client sends"
	Print "the information."	
	
	
;keep running until the escape key is pressed
	While Not KeyDown(1)
		
		svrStream = AcceptTCPStream(svr1)
		
		If svrStream Then
			Print ReadString(svrStream)
		End If
	
	Wend
	




And now for the client app.

;This is the client application for our game
Global client1

;Start the loop that will repeat untill the user is properly connected
Repeat
	
	;If the user mashes the ESC Key then End the Program
	If KeyDown(1) Then
		End
	End If
	

	;Connect to the TCP server
	client1 = OpenTCPStream("127.0.0.1", 8767)
	
	; test to see if it connected properly
	
	If client1 <> 0 Then
		Print "Connected 
		WriteString client1, "Hello"
		WriteString client1, Input("Write Message: ")
		
	Else 
		Print "Failed to Connect "
		Print "Press any key to retry"
		WaitKey 
	End If
Until client1 <> 0


WriteString client1, Input("Write Message: ")

WriteString client1, Input("Write Message: ")

WriteString client1, Input("Write Message: ")

;Go into the main loop of of the client application
Print "Starting Messenger"



After hours of trying to figure this out, i think it is time to try to get some help. Please let me know why my program will not let me send more than one group of text to my server. Like i said, I can send one group of text with WriteString, but then i can not send any more. Thank you for your time.


Robert M Jolly(Posted 2006) [#2]
How do i make the code show up like code? I will redo it so you guys can read it better when you tell me how.


b32(Posted 2006) [#3]
I think the [CODE][/CODE] should be lowercase.
There is also [CODEBOX] (also lowercase), use it for longer sources. It will make it easier to grab the code from it.


b32(Posted 2006) [#4]
Use ReadAvail after using AcceptStream:

I found that here: http://www.codersworkshop.com/viewpost.php?id=46928


DH(Posted 2006) [#5]
A. Readavail is a good start
B. Never assume that because you called any write<type>() that it actually writes when it's called. When you call WriteString(stream, val$) Blitz merely puts the data onto the TCP stack (in your pc), where the stack then handles when it goes out, and how it goes, and how it's acked. Since you're calling 3 of them, then ending the program, blitz is probably purging the TCP stack just after you call the writes, so the data never gets sent. So after the writes, send the client into a loop so you know all the data has been sent (loop it for at least 2 seconds, not delay, that will ensure that either the data made it, or it timed out).

Just a couple of suggestions


Robert M Jolly(Posted 2006) [#6]
Ok, I thank all of you for taking the time to do this. I have to go to the mall, but when i get back i will try all of your ideas and leave some feedback on how it worked. Thank you again guys!


Robert M Jolly(Posted 2006) [#7]
Darn, still no luck. I am going to have to uninstall my Blitz3d and reinstall it just to be sure. I use a lot of types (as we all do), and for some reason types do not show up when i click the types tab in the Blitz3D GUI. I dont know what is going on. I thank you all for your time. After the reinstall i will try again.


b32(Posted 2006) [#8]
No luck ? You mean it still sends only one string ? Here the new version sends 3 strings without a problem. I've tried it locally, on one p.c.
I think not showing the types is very common. For some reason they're allways null in the debug window.