I was just about to do a huge addition of the Zombie Yoga server by adding the ability to send of generic data to be saved into XML. As it turns out, the latest assignment uses the same concept. I often times use header bytes, usually reserved to 8 bytes to let the server/client know how the treat the data. So things such as packet number and packet type are stored within the first 8 bytes, usually through ints (series of chars makes the packets bloated, larger). It a little bit like how the latest assignment is setup, the only difference is that the signifyers are not sitting in the actual queue but are actually part of the end packet.
queues are great especially running the server and client using threads. For all the information necessary to send over, a
queue buffers up any items which need to be sent over from all the different threads and a main send thread handles the send by dequeing the items one by one as soon as they are pushed to the
queue . Its a neat way to keep things organized and avoid stalling the software in case there is any waiting time on sending the packets.
One odd thing I found about sending stuff over a c# socket is that I have to add stall time; I usually have a blocking for loop before each send. If I send the packets out too fast, the receiving end never gets them. Makes me wonder if it has to do with the way Microsoft's .net library handles sockets; maybe it would be a good idea to pull the stream out and write to it instead of write to the socket directly (probably does the same thing, but I cant be sure of that). I know java doesn't suffer of the same problem, at least on the android platform, so there must be a work around.