Sending a message to the client

Blitz3D Forums/Blitz3D Beginners Area/Sending a message to the client

Gun Ecstasy(Posted 2004) [#1]
I'm making a program that uses TCP streams. I'm making the server program right now. I know how to send a message to the sever from the client program, but what I'm not so sure of is how to send a message to the client. This is how I'm doing the server:

hServer=CreateTCPServer(6791)

If hServer=0
	RuntimeError "Failed to create server."
EndIf

hConWnd=CreateWindow("Connecting...",(1024-240)/2,(768-(60+29))/2,240,60+29,hMainWnd,1)
CreateLabel("Connecting...",80,20,70,20,hConWnd)
While 1
	TCPStream=AcceptTCPStream(hServer)
	If TCPStream
		If ReadString(TCPStream)="59872594"
			Exit
		EndIf
	EndIf
Wend

I'm doing all this based off what I read in the help section for the TCP commands. If the client wanted to send me a message after they have connected to the server, they would use:

; write stream to server
WriteString strmGame,"Mission Control, this is Apollo X ..."

As from the help section. How would I send a message to the client? Would this work?:

WriteString(hServer,"Hello")

How do I do it?

Also, I seems like I just treat TCP streams just like I would a file. So in that case, I could write a lot of data into a stream and then on the client side I could read it just like a regular file?


eBusiness(Posted 2004) [#2]
The TCP example is not that good, once connection is established with OpenTCPStream and AcceptTCPStream you can use the handles that those return both to send and recieve data on both sides, be aware that you need to check if there is anything to read using ReadAvail before reading, otherwise bugs will appear (you will likely read null,null,null etc).