About Store Forum Documentation Contact



Post Reply 
Three Socket Questions / Help Requests
Author Message
Chris Offline
Member

Post: #1
Three Socket Questions / Help Requests
Hi Grzegorz,

1. In:

Code:
Vec2 pos;
Int rcv=sock.receive(addr,&pos,SIZE(pos));

is SIZE(pos) used to define the amount of data to be received, to prevent buffer overflow, or is it used to make sure all the data is received (and thus vulnerable to buffer overflow?).

Also, in the socket tutorial, it is only sending Vec2 or null for the "Hello" packet, so it is easy to distinguish between them with:

Code:
if(rcv==SIZE(pos)) // do something with Vec2 data

But I need to be able to distinguish more than two packets (even if their both Vec2's, as they may contain different data meaning), with something like a Byte, and from that I need to know what type of packet is being sent (e.g. a chat packet, an encrypted login packet, etc). So, 2. Please could you write a quick code snippet to show a good way to identify between packets, and then receive their data of arbitrary types, which is not vulnerable to buffer overflow.

3. Does sock.block(false); make receiving in the Update method a multi-threaded server? I need a multi-threaded server to reduce the chance of packets not being dropped when two arrive at the same time.

Thanks,
Chris
01-04-2010 10:13 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Three Socket Questions / Help Requests
Hi,

1. the SIZE specifies maximum allowed space for receiving data (it's not vulnerable to buffer overflow)

2. you should send first a byte with a specific command, like make enum for commands
enum COMMAND
{
SENDING_PLAYER_POSITION,
SENDING_PLAYER_NAME,
}
after sending such command you can send appropriate data.
please note that networking isn't fully supported in EE, the existing functions provide low level access to the network so you can implement it on your own

3. you don't need multi-threading for this, packets are stored in temporary memory, and will be accessible when you request receiving them anytime later,
'block' method disables pausing when requesting for packet data when there is no data.
please google for ioctlsocket with FIONBIO parameter
01-05-2010 02:24 AM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #3
RE: Three Socket Questions / Help Requests
1. That's great.
2. Okay, i'll try this. I'm sorry for asking socket questions; i'm porting a custom server architecture which I originally wrote in Java sockets.
3. I think I see what you're saying, so if two messages arrive at the same time, they're not dropped.

Thanks again for your prompt support,
Chris
01-05-2010 05:15 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #4
RE: Three Socket Questions / Help Requests
2. So I should send two messages, the first to determine the type of data, the second to determine what's coming through? If doing this, with lots of clients, surely the order will get jumbled with the equivalent of race condition?

Or do you mean combining the enum byte with the data being sent? If this is the case, how can the first part of the message be read, to find out the byte type, then continue reading the rest of the message up to the size as determined by the byte enum (to prevent a buffer overflow)?

In Java I just had it read data in a stream, up to the id, then read the next N bits of data (as defined by the id type and tokenized) into whatever variables, with lots of validation guards. This is pretty much what i'm aiming for here.

Sorry about all this, but its very important that I get this part right for the security of the server.
01-06-2010 01:38 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: Three Socket Questions / Help Requests
you can pack this into one stream
File temp; temp.writeMem();
temp.putByte(command);
temp.put... data

when you have temp ready, you can copy the data from temp to Byte buf[1024] for example
temp.pos(0); temp.get(buf,..)
and then send the raw memory using sockets

there are just my advice but I'm no expert at real-time networking programming for games.
01-06-2010 01:58 AM
Find all posts by this user Quote this message in a reply
Post Reply