Ejemplo n.º 1
0
        /// <summary>
        /// Create a new TCP connection.
        /// </summary>
        public TCPConnection(TCPServer   TCPServer,
                             TcpClient   TCPClient)
            : base(new IPSocket(new IPv4Address((         TCPClient.Client.LocalEndPoint  as IPEndPoint).Address),
                                new IPPort     ((UInt16) (TCPClient.Client.LocalEndPoint  as IPEndPoint).Port)),
                   new IPSocket(new IPv4Address((         TCPClient.Client.RemoteEndPoint as IPEndPoint).Address),
                                new IPPort     ((UInt16) (TCPClient.Client.RemoteEndPoint as IPEndPoint).Port)))
        {
            this._TCPServer           = TCPServer;
            this._ServerTimestamp     = DateTime.Now;
            this.TCPClient            = TCPClient;
            this.ConnectionId         = TCPServer.ConnectionIdBuilder(this, this._ServerTimestamp, base.LocalSocket, base.RemoteSocket);
            this._IsClosed             = false;

            this.Stream               = TCPClient.GetStream();

            //_TCPClient.ReceiveTimeout           = (Int32) ConnectionTimeout.TotalMilliseconds;
            //_TCPConnection.Value.ReadTimeout    = ClientTimeout;
            //_TCPConnection.Value.StopRequested  = false;

            #if __MonoCS__
                        // Code for Mono C# compiler
            #else

            Thread.CurrentThread.Name = (TCPServer.ConnectionThreadsNameBuilder != null)
                                             ? TCPServer.ConnectionThreadsNameBuilder(this, this._ServerTimestamp, base.LocalSocket, base.RemoteSocket)
                                             : "TCP connection from " +
                                                     base.RemoteSocket.IPAddress.ToString() +
                                                     ":" +
                                                     base.RemoteSocket.Port.ToString();

            #endif
        }