C++ Host, BlitzMax Client - Network and Packets

BlitzMax Forums/BlitzMax Beginners Area/C++ Host, BlitzMax Client - Network and Packets

Goober(Posted 2010) [#1]
I have a C++ host that uses Winsocket.

I have my client, move north;
WriteInt(socketStream, info)

Host grabs the info using winsock;
recv();

Host needs to send a map update to the client
send();

PROBLEM:
The client does not seem to have any good functions for receiving on a socket stream. I tried using things such as ReadAvail and other methods/functions but nothing works.

I get the wrong data,
I sent in a char array 2MS999999, because that is how winsocket send() is used... but on the client side it gets random characters or numbers.



// I cannot find a good up-to-date tutorial on BlitzMax networking, can someone post code snip's or direct me to something proven to work?


AltanilConard(Posted 2010) [#2]
BlitzMax has excellent network functions. When you setup a socket in blitzmax and connect it to your C++ server, do you run in to any problems? I've created a C++ server in linux (with socket.h, not winsock) that worked just fine with my BlitzMax client.
Are you able to get decent communication between server and client (are you able to send bytes between the server and the client)?
You should send all your data between client and server in packets. In my game I use the following packet structure:
packet size in bytes (byte) - packet id (byte) - packet data


In my BlitzMax client, this is the method I use to receive packets:

		If _socket And _socket.ReadAvail() > 0
			size = _stream.ReadByte()
			packet_id = _stream.ReadByte()
			bank = CreateBank(size)
			ReadBank(bank, _stream, 0, size)
			' you read in the entire packet data at once
                        ' right now the bank contains all the packet data, you can extract 
                        ' it with the TBank functions of BlitzMax
                        ' something like HandlePacket(bank, packet_id)
		EndIf


If I misunderstood your point, or if you don't understand what I'm saying, I could post some examples later.


Goober(Posted 2010) [#3]
No that helps, so your first packet is the size of the incoming data correct?

Server Sends->5abcde

Client->
size = 5
ReadBank(...) will return abcde?


AltanilConard(Posted 2010) [#4]
ReadBank(bank, stream, size) will read size bytes from stream into bank. You will have to extract data from the bank with bank.PeekByte(n), where n is the byte position to read from.