public static IConnection Build(string hostName, int port, int timeout = 0)
 {
     try {
         var client = new TcpClient();
         client.Connect(hostName, port);
         var connection = new TcpClientConnection(client, timeout);
         return connection;
     }
     catch (SocketException ex) {
         throw new ConnectionException(string.Format("Unable to create a connection to the host '{0}' on the port '{1}'.", hostName, port), ex);
     }
 }
Exemplo n.º 2
0
 // ----- Internal logics
 private void Callback(IAsyncResult result)
 {
     try {
         var listener   = (TcpListener)result.AsyncState;
         var client     = listener.EndAcceptTcpClient(result);
         var connection = new TcpClientConnection(client);
         connection.Disconnected += ConnectionOnDisconnected;
         OnConnectionEstablished(new ConnectionEstablishedEventArgs(connection));
         listener.BeginAcceptTcpClient(Callback, listener);
     }
     catch (ObjectDisposedException) {}
 }
 // ----- Internal logics
 private void Callback(IAsyncResult result)
 {
     try {
         var listener = (TcpListener)result.AsyncState;
         var client = listener.EndAcceptTcpClient(result);
         var connection = new TcpClientConnection(client);
         connection.Disconnected += ConnectionOnDisconnected;
         OnConnectionEstablished(new ConnectionEstablishedEventArgs(connection));
         listener.BeginAcceptTcpClient(Callback, listener);
     }
     catch (ObjectDisposedException) {}
 }
Exemplo n.º 4
0
 public static IConnection Build(string hostName, int port, int timeout = 0)
 {
     try {
         var client = new TcpClient();
         client.Connect(hostName, port);
         var connection = new TcpClientConnection(client, timeout);
         return(connection);
     }
     catch (SocketException ex) {
         throw new ConnectionException(string.Format("Unable to create a connection to the host '{0}' on the port '{1}'.", hostName, port), ex);
     }
 }