Check Out Dave's New game for iPhone and iPod Touch: Smiled Out!

Chat Client/Server Part 1: Network Programming Primer and Packet Base Class

Pages: 1 2 3 4 5 6 7

A packet is going to have a single property. We need some way to tell our packet types apart. Even though we are using polymorphism and dot net, we cannot rely on typeof(object) because we will be transferring these objects over the network and reconstructing them on the other side. The computer we are connected to is just going to see a bunch of bytes, with no type information.

So our Packet base class is going to have a built-in, read only value which identifies the type of the packet. You will see this in use later.

Step 4: Add the Packet Type Code member and property. Place this code inside our Packet class.

1
2
        protected int _packetTypeCode = 0;
        public int PacketTypeCode { get { return _packetTypeCode; } }

_packetTypeCode is protected because the child classes who inherit from this protocol will need to be able to set the value. The public property is read-only because we don’t want our clients who use this library to monkey around with our packet data too much!

Pages: 1 2 3 4 5 6 7


Follow Dave on Twitter
  1. [...] See the original post here: Program With Dave » Blog Archive » Chat Client/Server Part 1 … [...]

  2. [...] the original post:  Program With Dave » Blog Archive » Chat Client/Server Part 1 … By admin | category: chat software | tags: dot-net, manifest-itself, p2p-video, result, [...]

  3. [...] Address Already In Use: JVM_Bind:8080″. Now, if you’ve read my sockets tutorial network primer, you know that a port can only be bound for listening once. So apparently I had another process on [...]

  4. [...] you have not read Part 1 of this Multi-Post tutorial, check it out now. This tutorial will rely on the code written in that [...]

  5. [...] you have not read Part 1 and Part 2 of this network tutorial series, please do so now. The code in this post will build upon [...]

Leave a Reply