Click here to Skip to main content
15,894,825 members
Articles / Programming Languages / C#

Design and Implementation of a High-performance TCP/IP Communications Library

Rate me:
Please Sign up or sign in to vote.
4.89/5 (57 votes)
3 Aug 2008CPOL13 min read 155.5K   4.4K   284  
A TCP/IP Communications Library, designed to handle client-server data transmission for a massive multiplayer online game.
using System;
using System.IO;
using System.ComponentModel;
using System.Net.Sockets;
using System.Net;

namespace BrainTechLLC.EmlenMud.Interfaces
{
	public interface ICommunicationsMessage
	{
		object MessageContents { get; set; }
		IMessageHeader Header { get; set; }
		byte[] ReadBytesForTransmission();
		int MessageType { get; }
	}

	public interface IMessageHeader
	{
		void WriteHeaderToStream(MemoryStream ms);
		int HeaderSize { get; }
		int MessageType { get; set; }
		int MessageSize { get; set; }
		void ReadFromStream(BinaryReader binaryReader);
	}

   //public class ObjectEventArgs : EventArgs
   //{
   //    public ICommunicationsMessage Message { get; set; }
   //    public ObjectEventArgs(ICommunicationsMessage message) { Message = message; }
   //}

   public class ObjectEventArgsNonRef<T> : EventArgs
   {
	   public T obj { get; set; }
	   public ObjectEventArgsNonRef(T item) { obj = item; }
   }

   public class ObjectEventArgsNonRef<T1, T2> : EventArgs
   {
	   public T1 obj1 { get; set; }
	   public T2 obj2 { get; set; }
	   public ObjectEventArgsNonRef(T1 item1, T2 item2) { obj1 = item1; obj2 = item2; }
   }

   public class ObjectEventArgsNonRef<T1, T2, T3> : EventArgs
   {
	   public T1 obj1 { get; set; }
	   public T2 obj2 { get; set; }
	   public T3 obj3 { get; set; }
	   public ObjectEventArgsNonRef(T1 item1, T2 item2, T3 item3) { obj1 = item1; obj2 = item2; obj3 = item3; }
   }

   public class ObjectEventArgs<T> : EventArgs where T : class
   {
	   public T obj { get; set; }
	   public ObjectEventArgs(T item) { obj = item; }
   }

   public class ObjectEventArgs<T1, T2> : EventArgs
	   where T1 : class
	   where T2 : class
   {
	   public T1 obj1 { get; set; }
	   public T2 obj2 { get; set; }
	   public ObjectEventArgs(T1 item1, T2 item2) { obj1 = item1; obj2 = item2; }
   }

   public class ObjectEventArgs<T1, T2, T3> : EventArgs
	   where T1 : class
	   where T2 : class
	   where T3 : class
   {
	   public T1 obj1 { get; set; }
	   public T2 obj2 { get; set; }
	   public T3 obj3 { get; set; }
	   public ObjectEventArgs(T1 item1, T2 item2, T3 item3) { obj1 = item1; obj2 = item2; obj3 = item3; }
   }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Troppus Software
United States United States
Currently working as a Senior Silverlight Developer with Troppus Software in Superior, CO. I enjoy statistics, programming, new technology, playing the cello, and reading codeproject articles. Smile | :)

Comments and Discussions