Game Development Community

Exchanging client-server binary data?

by Isidore · in Torque Game Engine · 01/26/2003 (11:26 am) · 6 replies

Hello to everyone!

I would like to know if somebody knows whether it is possible to send data from client to server, other than text and numbers or not?

I saw a few posts about this, using commandToServer() and commandToClient(), which works just fine with strings and numbers.
(like http://www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=5493)

But is it possible, for instance, to send a buffer containing binary data?

(basic e.g: if we try to pass data from a binary file (or whatever) through the torque network)

I tried to use commandToServer using custom binary buffesr, and I got corrupt data at reception.
Is it my code, or was this not designed to handle binary data?

I hope somebody can help me.

Cheers,

Isidore

#1
01/26/2003 (4:47 pm)
There are of course a lot of possibilities, but you might be better served transferring your data using the existing file transfer code (which is used for mission data), or using the Torque networking code directly (ie, not via script, but rather with a C/C++ object).

Failing that, try converting the binary data to hexadecimal, transferring that, then converting back. That's definitely the simplest fix.
#2
01/27/2003 (2:55 am)
Thanks for your reply Ben.

Quote:or using the Torque networking code directly (ie, not via script, but rather with a C/C++ object)

I see. That is what I am currently trying to do, but it seemed like a tedious work :)
I ll keep on working on it anyway.

Quote:Failing that, try converting the binary data to hexadecimal, transferring that, then converting back.

Do you mean "ascii"?
If so, what I tried to do was converting the data using base64 encoding/decoding.

I then discovered that the way I was following (using commandToServer /commandToClient) was allowing only transfer of 256 bytes max of data, which forced to reduce the effective size of data to about 190 bytes (due to base64 encoding), which force to send more packets of data.
Not sure if this is the best way to do it, but I ll try again.

Thanks for your info anyway!

Cheers,

Isidore
#4
01/27/2003 (4:02 am)
Sorry I couldn't be more help... Good luck solving your problem :)
#5
01/28/2003 (2:39 am)
ok base64 encoding works fine, provided the encoded data stays below 256 bytes.

not very optimized, but, that ll do for a while :)

let's consider the problem solved and this post closed.

Cheers,

Isidore
#6
02/03/2007 (1:08 pm)
Sorry for reviving a dead post, but after searching the forums for a similar solution and failing, i figured i would post what I used for custom protocols within Torque. Custom NetEvents!

e.g.

class incomingVoiceBlock : public NetEvent
    {
       typedef NetEvent Parent;
    public:
       incomingVoiceBlock(const voiceBlock_t * _dataBlock = NULL)
	   {
		   mGuaranteeType = Unguaranteed;
		   if (_dataBlock)
				memcpy(&dataBlock, _dataBlock, sizeof(outVoiceBlock_t));
	   }

       ~incomingVoiceBlock()
	   {
	   }
       
       virtual void pack   (NetConnection *conn, BitStream *bstream)
	   {
		   bstream->write(dataBlock.dataSize);
		   bstream->write(dataBlock.dataSize, dataBlock.data);
		   bstream->write(conn->getId());
	   }
       virtual void write  (NetConnection *conn, BitStream *bstream)
	   {
	   }
       virtual void unpack (NetConnection *conn, BitStream *bstream)
	   {
		   voiceBlock_t	   serverDataBlock;	
		   bstream->read(&serverDataBlock.dataSize);
		   bstream->read(serverDataBlock.dataSize, serverDataBlock.data);
		   bstream->read(&serverDataBlock.player);

		   GameConnection::getConnectionToServer()->
				getVoiceComm()->decodeBlock(&serverDataBlock);
	   }
       virtual void process(NetConnection *conn)
	   {
	   }
	   DECLARE_CONOBJECT(incomingVoiceBlock);
	   voiceBlock_t	   dataBlock;	
    };
    
    IMPLEMENT_CO_CLIENTEVENT_V1(incomingVoiceBlock);

The docs have a nice section on them here.

Guess we should RTFM first. :)

www.garagegames.com/docs/tge/engine/classNetEvent.php