   networking engine question
  i was thinking about how i could write a communications system for my game before and i was wondering if it would work.  all i have is some pseudo code and the idea is still changing.  basically i would create a class called netdata or something and put an Id item in it.  the id item would tell the receiver what type of data is in the object - message, movement, item drop etc.for example:class NetData {  int DataId;  string Data;};if (DataId = 1){  //DataId 1 is a message from another player   //do a print function on Data here.}else if (DataId = 2){  //dataid 2 is player movement  //parse Data  //update players coordinates and render}If that wouldnt work, or if there is a better way of doing it, please enlighten me =).  I'm sorry if its confusing the way i'm asking, its 5:30 am here and i'm about to fall asleep. =P   
  I would create a packet header, which if using TCP uses a length feild, packet type, and a delimeter.  The length tells you how long the datafield is, the type tells you the struct used for the packet (simple define for each packet type) and the delimeter marks the end of the packet stream, which confirms that this packet is of the correct length given before in packet length.   ;You can copy data structs (records) into your buffer directly (and then back out on the receiving end) and every struct would have a CHAR or BYTE as its first element to say what kind it is.  Make sure you set packing to 1 to save space....  Binary data will often be more compact than the equivalent text (saves on encode/decode overhead).   You should use a switch() statement instead of many if-then-else (you may have dozens of different message types (each event type might have a different one).Group messages together (dont send each as a packet -- this causes alot of overhead).   I di this myself with UDP, but there must be ways of telling TCP not to send a packet on every write (you would have some kind of 'flush' that you would use to force the last one to be sent off for the end of each turns transmission)..;  TCP already groups transmission together throug Nagle's algorithm. Most game developers actually prefer to turn it off since they are going for speed as opposed to network utilizations.  (UDP does not do this)Also the above user I assume is talking about storing your actual struct in bytecode as opposed to numerical representation of text. Hence: memcpy(packet, (unsigned char *)struct, sizeof(struct)); as opposed to representing each numerical value by its digit counterpart. packet[0] = 1; packet[1] = 2; packet[2] = 3; for representing the number "123"(you can pack it into one char: packet[0] = 123;).You can copy data structs (records) into your buffer directly (and then back out on the receiving end) and every struct would have a CHAR or BYTE as its first element to say what kind it isBasically use the above memcpy method to copy your struct, do not represent numerical values as individual chars.  I assume the poster meant including a "char type;" field within your struct, so that when you memcpy the struct to your char buffer, the first byte will be the type of packet.  This does not really matter in how you  implement it, because if you are using TCP you can just include this information when writing you TCP packet header, since you will need a packet length field anyways, you can include it then.example:[length][packet type][mem copied struct of your packet][delimeter]or if you included it in your structs themselve it would be[length][packet type | rest of copied struct][delimeter]Just realize that TCP is stream based (like reading a file) and UDP is packet based.;  thanks, this is all good, but i'm still relatively new to network programming.  would you happen to know of any good references for it?   ;  I'm also currently busy with my first networked game, got it to send packets back to 127.0.0.1.  For help starting, look at the networking forum's FAQ, they've got some great links.  I'm using the ENet library and i really like it. It's easy to use as well. There's a link to it somewhere in the FAQ as well. Somewhere in there's some links to how the Q3 networking system works, check that out, as well as the Unreal one, to hear how the pro's do it. Really worth the read.  Good Luck.. =]   ;  thanks much =)  its a big help   ;  if doing windows programming, I found this resource quite useful:http://tangentsoft.net/wskfaq/   