public void SetUp() { if (!HighPerformance) { ClientSendBuffer = new ConcurrentCircularBuffer<NetworkData>(BufferSize); ClientReceiveBuffer = new ConcurrentCircularBuffer<NetworkData>(BufferSize); ServerReceiveBuffer = new ConcurrentCircularBuffer<NetworkData>(BufferSize); } ClientReceived = new AtomicCounter(0); ServerReceived = new AtomicCounter(0); _clientExecutor = new AssertExecutor(); _serverExecutor = new AssertExecutor(); var serverBootstrap = new ServerBootstrap() .WorkerThreads(2) .Executor(_serverExecutor) .SetTransport(TransportType) .SetEncoder(Encoder) .SetDecoder(Decoder) .SetAllocator(Allocator) .SetConfig(Config) .Build(); _server = serverBootstrap.NewConnection(Node.Loopback()); _clientConnectionFactory = new ClientBootstrap() .Executor(_clientExecutor) .SetTransport(TransportType) .SetEncoder(Encoder) .SetDecoder(Decoder) .SetAllocator(Allocator) .SetConfig(Config) .Build(); }
private static void Main(string[] args) { var host = IPAddress.Any; var port = 9991; Console.Title = "Server"; Console.WriteLine("Starting server on {0}:{1}", host, port); var executor = new TryCatchExecutor(exception => Console.WriteLine("Unhandled exception: {0}", exception)); var bootstrapper = new ServerBootstrap() .WorkerThreads(2) .Executor(executor) .SetTransport(TransportType.Tcp) .Build(); var server = bootstrapper.NewReactor(NodeBuilder.BuildNode().Host(host).WithPort(port)); server.OnConnection += (address, connection) => { Console.WriteLine("Connected: {0}", address); connection.BeginReceive(Receive); }; server.OnDisconnection += (reason, address) => Console.WriteLine("Disconnected: {0}; Reason: {1}", address.RemoteHost, reason.Type); server.Start(); Console.WriteLine("Running, press any key to exit"); Console.ReadKey(); Console.WriteLine("Shutting down..."); server.Stop(); Console.WriteLine("Terminated"); }
private static void Main(string[] args) { Port = args.Length < 1 ? DEFAULT_PORT : int.Parse(args[0]); var ip = IPAddress.Any; Console.WriteLine("Starting echo server..."); Console.WriteLine("Will begin listening for requests on {0}:{1}", ip, Port); var bootstrapper = new ServerBootstrap() .WorkerThreads(2) .SetTransport(TransportType.Udp) .Build(); var reactor = bootstrapper.NewReactor(NodeBuilder.BuildNode().Host(ip).WithPort(Port)); reactor.OnConnection += (node, connection) => { ServerPrint(node, string.Format("Accepting connection from... {0}:{1}", node.Host, node.Port)); connection.BeginReceive(Receive); }; reactor.OnDisconnection += (reason, address) => ServerPrint(address.RemoteHost, string.Format("Closed connection to... {0}:{1} [Reason:{2}]", address.RemoteHost.Host, address.RemoteHost.Port, reason.Type)); reactor.Start(); Console.ReadKey(); }
public void UdpProxyServer_should_bind_to_ephemeral_port() { var server = new ServerBootstrap().SetTransport(TransportType.Udp).Build().NewReactor(NodeBuilder.BuildNode().Host(IPAddress.Any).WithPort(0)); server.Start(); Assert.AreNotEqual(0, server.LocalEndpoint.Port); server.Stop(); }
public void TcpProxyServer_connection_adapter_should_bind_to_ephemeral_port() { var server = new ServerBootstrap().SetTransport(TransportType.Tcp).Build().NewReactor(NodeBuilder.BuildNode().Host(IPAddress.Any).WithPort(0)).ConnectionAdapter; server.Open(); Assert.AreNotEqual(0, server.Local.Port); server.Close(); }
public ServerBootstrap(ServerBootstrap other) : base(other) { UseProxies = other.UseProxies; BufferBytes = other.BufferBytes; WorkersShareFiber(other.UseSharedFiber); Workers = other.Workers; InternalExecutor = other.InternalExecutor; }
public void UdpConnection_should_bind_to_outbound_ephemeral_port() { var serverAddress = NodeBuilder.BuildNode().Host(IPAddress.Loopback).WithPort(13171); var server = new ServerBootstrap().SetTransport(TransportType.Udp).Build().NewReactor(serverAddress); var connection = new ClientBootstrap().SetTransport(TransportType.Udp) .Build() .NewConnection(Node.Loopback(), serverAddress); server.Start(); connection.Open(); Assert.NotEqual(0, connection.Local.Port); connection.Close(); server.Stop(); }
public TcpServerFactory(ServerBootstrap other) : base(other) { }
protected ServerFactoryBase(ServerBootstrap other) : base(other) { }
public UdpServerFactory(ServerBootstrap other) : base(other) { }
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; } }
private void Run() { var bootstrapper = new ServerBootstrap() .WorkerThreads(4) .SetTransport(TransportType.Udp) .Build(); _reactor = bootstrapper.NewReactor( NodeBuilder.BuildNode() .Host(HostIp) .WithPort(HostPort)); _reactor.OnConnection += (node, connection) => { //ServerPrint(node, // string.Format("Accepting connection from... {0}:{1}", node.Host, node.Port)); connection.BeginReceive(UdpPackerReceiveCallback); }; //reactor.OnDisconnection += (reason, address) => ServerPrint(address.RemoteHost, // string.Format("Closed connection to... {0}:{1} [Reason:{2}]", address.RemoteHost.Host, address.RemoteHost.Port, reason.Type)); _reactor.Start(); }