Exemplo n.º 1
0
        /// <summary>
        ///     This constructor simplifies the process of correctly creating a socket,
        ///     connecting and creating an instance of TCPConnection, where the stream
        ///     and other I/O properties are exposed and managed.  The constructor simplifies
        ///     descendents by accepting only one parameter where both the host and port can
        ///     be specified, allowing the developer to avoid constructor hell.
        /// </summary>
        /// <param name="aHost">
        ///     This string parameter can contain both the host and port, or just
        ///     the host name.  When including the port with the host use a ":" to seperate
        ///     the two, eg "localhost:80".
        /// </param>
        public TCPClient(string aHost)
        {
            Socket xSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            int    xPort;

            string[] xHostParts = aHost.Split(':');
            if (xHostParts.Length == 2)
            {
                xPort = int.Parse(xHostParts[1]);
            }
            else
            {
                xPort = GetDefaultPort();
                if (xPort == -1)
                {
                    throw new Exceptions.Exception("No default port specified.");
                }
            }
            xSocket.Connect(new IPEndPoint(ResolveAddress(xHostParts[0]), xPort));
            mConnection = new TCPConnection(xSocket);
        }
Exemplo n.º 2
0
 /// <summary>
 ///     This constructor is here to give the developer more control in the creation
 ///     of there TCPConnection.  Once having created the TCPConnection it is passed
 ///     as a parameter into the consctuctior.
 /// </summary>
 /// <param name="aConnection">TCPConnection for the TCPClient</param>
 public TCPClient(TCPConnection aConnection)
 {
     mConnection = aConnection;
 }
Exemplo n.º 3
0
        protected void ConnectionThreadRun(object aSocket)
        {
            var xConnection = new TCPConnection((Socket)aSocket);

            mDoRun(xConnection);
        }