Some questions about UDP, Bitfields and packet data.

Started by
1 comment, last by gimp 23 years, 11 months ago
Hello, thanks for taking the time to have a read. A few questions... -Does anyone know of any tutorials about UPD? I''ve been reading up and it looks like I only have to upen a single socket to recieve UPD datagrams. -What is a bitfield? Is it just like BYTE data[16] -When I collect packets on the server and send them to all clients, how will my code at the other end know where each hunk of data ends? Are NULL''s really unique when I''m setting all bits? Should I send the first part of the hunk as a data size in bytes? Many thanks.. Chris
Chris Brodie
Advertisement
Check out this site for some info on how a server - client game is structured.

http://www.codewhore.com/

You can organize the data transfer between your client and server around serialized objects, if your using objects. Implement a write and read function per object which recives an input or output stream from which it can read or write. A network connection can be abstracted to function like any other stream (ie. file stream). You''ll need to preface the packet stream with the packet id so you know what packet type it is. You can either embeded the packet size in the stream or give it a fixed size at compile time, both are easily implemented. This is just one way to do it.

You can use an int to represent a bitfield. They are usually 32 bits on modern cpus. I suggest creatting a bitfield datatype class. For instance

class Bitfield {
public:

Bitfield(){field = 0;}
virtual ~Bitfield();

void activate_flags(unsigned int flag)
{
field /= flag;
}

void deactivate_flags(unsigend int flag)
{
field &= ~flag;
}

unsigned int check_flags(unsigend int flag)
{
return (flag&field);
}

//serailzing functions as explained above

bool write(outstream *out);
bool read(instream *in);

private:

unsigned int field;

};

This should give you some ideas about how to impelement a bitfield class. I dont know if the above compiles i just wrote it, but it should. You can set more than one flag at a time by combining them like

bitfield.activate_flag(FLAG1/FLAG2/FLAG3);

using the logical or.


Good Luck.

-ddn

apparenlty this messagebaord doesn''t allow you to use the logical or operator and replaces it with a backslash. Well just make sure to replace the (/) with the logical or operator.

Good Luck

-ddn

This topic is closed to new replies.

Advertisement