   Networking SubSystem for GameEngine
  Hi all,I'm in the process of developping a game engine to build a demo out of it. I'm now looking at the networking sub-system. I've red alot posts and tuts and a few questions are poping out in my mind, that i need answered first, before digging into the design of the sub-system.My game-engine is based upon C# and MDX, and since DirectPlay is being deprecated i'm turning to System.Net.Socket namespace to build the networking sub-system. Also, i dont wanna use another lib, since i'm doing this as "on-the-side" research project for my university courses.So,1. Would it be necessary to have 1 socket on the server to listing up to connection request from clients. Then, create a new socket for each "connected" client. I saw that a few times... Or just 1 socket would be ok for both? Or maybe 1 socket for listing connection request and 1 socket for game processing of messages, this one seems to be just enought to me.2. I've also seen posts talking about "channels" when referring to UDP sockets. What are they, can't find anything related to this in MSDN. In thoses posts they were talking of a limit of 32ips by channel and 32channels per socket!?. Per msdn, it's seem that you can send udp packet to an unlimitted numbers of ips since the protype of the methode is Socket.SendTo(IPAddress address, byte[] data).3. As udp is a connection-less protocol and it's unreliable. If you want to be able to guarante delivery we need to implement a Syn/Ack "paradigm" as in TCP. This pop a little question. When you send a udp packet flagged "Guaranteed Delivery", the receiver simply answer with a Ack packet with the sequence number. This ack packet cannot be a "Guaranteed Packet" because that could create a "infinite loop" of ack? right? So if that ack packet get lost, the sender will simply resend the packet to the client. I'm thinking that this could cause problems when you get high packet lost ratio... maybe i'm overlooking something...4. Another thing of udp is the "out-of-sequence" problem that may arise. Is simply ignoring the packet that is out of sequence is enought when you send absolute game update (meaning, no delta-compression, relative-updates?5. The network message / packet structures. In my preliminary design i'm making distinctions between packet and game message. A packet is a container(seq, ack, lenght, payload) to move game message back and forth between client/server. My game message would be structures identifiable by an ID, maybe and enumeration. Is this a normal design, effective design, there is other solutions or design to this ?6. And last, but not the least, to encode/decode the packet/game-message to an array of byte, since SendTo needs an array of byte, is there a miracle method somewhere ;) BinaryFormatter is adding alot of overhead to the byte array (more then 50%). And writing a encoder/decoder for each message type using a StreamWriter/StreamReader, even if this seem to be the best solution,  involve alot of work (alot of overhead on my side :) )Thanks in advance for your patience...Jonathan   
  1. With TCP, you create one socket for listening, and then you get one socket created per client you accept. With UDP, you typically only create a single socket for all your sending/receiving needs (because that works best through NAT).2. Those posts are talking about a library layered on top of UDP; there's a list of such libraries in the Forum FAQ.3. Yes, you will need to re-send if you don't get the ack. If you have a high packet loss, you will have worse problems than just excessive packet re-sends, though, so that's not a problem to worry too much about.4. Yes, for most typical implementations.5. That's a fine start, although I'd put as many messages as can fit into a single network packet. Network packets need sequence numbers etc; messages just need destination, type and data. You will know whether a specific message made it by looking at which packets made it, and you can choose to re-send different lost messages in different packets.6. Marshalling/Demarshalling is always annoying, because you need some way to tie a language construct to a binary format. If you're OK with living with less efficient data structures in run-time (say, hash tables of values) then you can describe your packets using some language like XML, and use a data-driven stream reader/writer. Another option is to write some C++ glue to do the byte operations, as some of them are rather easier to express in C++ with pointers.   ;  Thanks for your reply...That's confirming my firsts thoughts...So, now, let begin/finalyse that sub-systemHave a nice day,Jonathan   ;  I'm also in the process of designing such a thing (pure UDP network system). It's quite interesting. Hope you enjoy it as much as I do :)   ;  Yes it really cool, but it almost all new to me... I know alot about network, i've worked in the field for 3 years. If you wish, i would be put to design here, so maybe we can shares some ideas?a+Jonathan   ;Quote:Original post by LowRad6. And last, but not the least, to encode/decode the packet/game-message to an array of byte, since SendTo needs an array of byte, is there a miracle method somewhere ;) BinaryFormatter is adding alot of overhead to the byte array (more then 50%). And writing a encoder/decoder for each message type using a StreamWriter/StreamReader, even if this seem to be the best solution, involve alot of work (alot of overhead on my side :) )If you're using C#, I recommend taking advantage of the built in conversions...From Byte Array to stringbyte[] m_ary =  System.Text.Encoding.ASCII.GetBytes("Testing")From string to Byte arraystring final =  System.Text.Encoding.ASCII.GetString(m_ary)