Exemple #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="connection">The socket connection.</param>
 /// <param name="server">The TcpServer instance.</param>
 public ConnectionState(Socket connection, TcpServer server)
 {
     this.connection = connection;
     this.server     = server;
 }
        /// <summary>
        /// This is the prefered manner for closing a socket connection, as it
        /// nulls the internal fields so that subsequently referencing a closed
        /// connection throws an exception. This method also throws an exception
        /// if the connection has already been shut down.
        /// </summary>
        public void Close()
        {
            if (server == null)
            {
                throw new TcpLibException("Connection already is closed.");
            }

            connection.Shutdown(SocketShutdown.Both);
            connection.Close();
            connection = null;
            server = null;
        }
        private void CreateRemote()
        {
            if (_server == null)
            {
                string RemoteConnectionString = ConfigurationManager.AppSettings["TCPServer"];
                var remote = RemoteConnectionString.Split(new char[] { ':' });
                var hostname = remote[0];
                var port = remote[1];

                _server = new TcpServer(hostname, int.Parse(port));
                _server.Connected += OnRemoteConnected;
            }
            else
            {
                _server.StopListening();
            }

            _server.StartListening();
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="connection">The socket connection.</param>
 /// <param name="server">The TcpServer instance.</param>
 public ConnectionState(Socket connection, TcpServer server)
 {
     this.connection = connection;
     this.server = server;
 }