Click here to Skip to main content
15,886,806 members
Articles / Web Development / ASP.NET

P2P Communication - Proxy Listeners and Proxy Clients

Rate me:
Please Sign up or sign in to vote.
3.67/5 (3 votes)
19 Apr 2008CPOL4 min read 58.6K   2.2K   48  
Implementation of Listener and Client objects that communicate through a Web proxy
using System;
using System.Collections.Generic;
using System.Text;

namespace ProxyCommon
{
    public class RegisterMessage : Header
    {
        #region Memeber Variables
        private string serverName;
        #endregion

        #region Constructor
        public RegisterMessage(short SenderEndPoint, short RecieverEndPoint, string ServerName)
            : base(MessageType.Register, SenderEndPoint, RecieverEndPoint)
        {
            serverName = ServerName;
            ContentSize = serverName.Length;
        }
        public RegisterMessage(byte[] SerializationData) : base(SerializationData)
        {
            int bSize = base.GetSize();
            byte[] thisBytes = new byte[SerializationData.Length - bSize];
            Array.Copy(SerializationData, bSize, thisBytes, 0, thisBytes.Length);
            serverName = ASCIIEncoding.ASCII.GetString(thisBytes);
        }
        #endregion

        #region Overrides
        public override int GetSize()
        {
            return serverName.Length;
        }
        public override byte[] ToByteArray()
        {
            int bSize = base.GetSize();
            byte[] bytes = new byte[GetSize() + bSize];
            base.ToByteArray().CopyTo(bytes, 0);
            ASCIIEncoding.ASCII.GetBytes(serverName).CopyTo(bytes, bSize) ;
            return bytes;
        }
        #endregion

        #region Properties
        public string ServerName
        {
            get { return serverName; }
        }
        #endregion
    }
}

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)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions