예제 #1
0
 public static RemoteConnection CreateConnection(Role role, INode socketAddress, int poolSize, IHeliosConnectionHandler upstreamHandler)
 {
     if (role == Role.Client)
     {
         var connection = new ClientBootstrap().SetTransport(TransportType.Tcp)
                          .SetOption("TcpNoDelay", true)
                          .SetEncoder(Encoders.DefaultEncoder) //LengthFieldPrepender
                          .SetDecoder(Encoders.DefaultDecoder) //LengthFieldFrameBasedDecoder
                          .WorkerThreads(poolSize).Build().NewConnection(socketAddress);
         var remoteConnection = new RemoteConnection(connection, upstreamHandler);
         remoteConnection.Open();
         return(remoteConnection);
     }
     else //server
     {
         var connection = new ServerBootstrap().SetTransport(TransportType.Tcp)
                          .SetOption("TcpNoDelay", true)
                          .SetEncoder(Encoders.DefaultEncoder) //LengthFieldPrepender
                          .SetDecoder(Encoders.DefaultDecoder) //LengthFieldFrameBasedDecoder
                          .WorkerThreads(poolSize).Build().NewConnection(socketAddress);
         var remoteConnection = new RemoteConnection(connection, upstreamHandler);
         remoteConnection.Open();
         return(remoteConnection);
     }
 }
예제 #2
0
 public static RemoteConnection CreateConnection(Role role, INode socketAddress, int poolSize, IHeliosConnectionHandler upstreamHandler)
 {
     if (role == Role.Client)
     {
         var connection = new ClientBootstrap().SetTransport(TransportType.Tcp)
             .SetOption("TcpNoDelay", true)
             .SetEncoder(Encoders.DefaultEncoder) //LengthFieldPrepender
             .SetDecoder(Encoders.DefaultDecoder) //LengthFieldFrameBasedDecoder
             .WorkerThreads(poolSize).Build().NewConnection(socketAddress);
         var remoteConnection = new RemoteConnection(connection, upstreamHandler);
         remoteConnection.Open();
         return remoteConnection;
     }
     else //server
     {
         var connection = new ServerBootstrap().SetTransport(TransportType.Tcp)
             .SetOption("TcpNoDelay", true)
             .SetEncoder(Encoders.DefaultEncoder) //LengthFieldPrepender
             .SetDecoder(Encoders.DefaultDecoder) //LengthFieldFrameBasedDecoder
             .WorkerThreads(poolSize).Build().NewConnection(socketAddress);
         var remoteConnection = new RemoteConnection(connection, upstreamHandler);
         remoteConnection.Open();
         return remoteConnection;
     }
 }