• Advertisement

Archived

This topic is now archived and is closed to further replies.

Some questions about UDP, Bitfields and packet data.

This topic is 6474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites

  • Advertisement