Talk:Binary Packet
From GPWiki
The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server. However, the GPWiki forums are still active! Come say hello. You mention that you can use either 1 or 2 bytes, but how about mentioning a "hybrid system" where you use both 1 and 2 bytes. Obviously, the 1-byte IDs would be for the most common packets. This system can be set up like: 1-Byte Packets: Byte1 = 0-200 Byte2 = 201-255 If a value of 201-255 is grabbed for the ID of the first byte, a second byte will be grabbed to complete the packet ID. This allows for large games to have common events such as walking and fighting as a single byte and more uncommon events like doing a triple backflip off a purple elephant as 2 bytes. --Spodi 19:10, 21 September 2006 (EDT) that's what I meant by the 1 byte system. I just started writing this yesterday, it's my first article. I will clarify it more. Selt got me thinking about how many people don't know how to design packets efficiently so I wrote what you saw really quick to get ideas out then I went to bed.
[edit] Octet vs ByteBytes needn't be 8 bits, though they are at least 8 bits. Use octet if you mean exactly 8 bits --pfeilspitze 17:20, 22 September 2006 (EDT)
[edit] Bitwise packets"Most of the time it's overkill to use bit packets though." Not sure if this is referring to using packets on a bit-basis (so instead of defining how many bytes you want to take out, you define it by bits), but to me, this reads, "using bits for packets is overkill". Personally, bit flags on packets play one of the largest roles in packets for me, since you can easily define what information is packed with bit flags. While we're at it, maybe examples on using bit flags would be nice? ;) --Spodi 16:21, 3 March 2007 (EST) [edit] VB.NET version added: and thanks spodiThere I finally decided to add the vb.net byte packet I used in one of my games. Oh yeah and thanks Spodi for posting your VB6 byte packet. [edit] The .NET code is unnecessaryIn .Net you can use System.IO.BinaryReader and BinaryWriter with a stream class. There is no need to reinvent the wheel with a custom buffer class. It would be more useful to demonstrate the usage of these classes in creating packets than the current VB.Net source code. [edit] Added info on binary reader and writerthanks for mentioning that. I also included links to MSDN since the docs explain it. --Sirisian 17:45, 12 April 2007 (EDT) [edit] .NET code elaborationMaybe there should be more elaboration on how to do the BinaryWriter/Reader with .NET. Took me bit of digging and guessing to find out how to write directly to a byte array. class Program { static void Main(string[] args) { byte[] b = new byte[255]; Stream s = new MemoryStream(b, true); BinaryWriter w = new BinaryWriter(s); w.Write("hello"); w.Close(); s.Close(); Output(b); Console.ReadLine(); } static void Output(byte[] b) { for (int i = 0; i < b.Length; i++) { Console.Write(b[i].ToString() + ","); } } } Just a little rough mock-up. Those MSDN links didn't help much, since most all reference to BinaryWriter/Reader is with a FileStream. --Spodi 06:24, 11 November 2007 (EST) |


