2011-03-10, 11:57 AM
The Minecraft Protocol is a PITA to work with.
Let me first describe it for those of you who don't know: "packets" are simply a single-byte packet identifier followed by specific data structures, your primitives: bytes, shorts, ints, strings, floats, doubles.
There is no packet length prefixed.
That may be fine if every packet has a static length. But there are strings. How are they implemented? A unsigned short denoting the length, followed by the string encoded in UTF8.
The Notchian server implements this protocol using (>four) thread(s)-per-connection: it simply reads the packet using blocking calls. That works, but it doesn't scale very well. So now we have to think of a way to implement this using some form of asynchronous networking: async sockets, NIO, MINA...
My approach on my (now scrapped and deleted) Minecraft emulator project was to attempt to read out the entire packet every time we receive data. That worked, but it felt hacky.
I haven't been able to think of better ways.
For more information on the Minecraft Protocol, http://mc.kev009.com/Protocol
Let me first describe it for those of you who don't know: "packets" are simply a single-byte packet identifier followed by specific data structures, your primitives: bytes, shorts, ints, strings, floats, doubles.
There is no packet length prefixed.
That may be fine if every packet has a static length. But there are strings. How are they implemented? A unsigned short denoting the length, followed by the string encoded in UTF8.
The Notchian server implements this protocol using (>four) thread(s)-per-connection: it simply reads the packet using blocking calls. That works, but it doesn't scale very well. So now we have to think of a way to implement this using some form of asynchronous networking: async sockets, NIO, MINA...
My approach on my (now scrapped and deleted) Minecraft emulator project was to attempt to read out the entire packet every time we receive data. That worked, but it felt hacky.
I haven't been able to think of better ways.
For more information on the Minecraft Protocol, http://mc.kev009.com/Protocol

