Client bootstrap for outbound connections
Inheritance: AbstractBootstrap
Exemple #1
0
        public Entry()
        {
            Log = null;
            _loopContinue = true;

            rx = new Regex(@"([\d.]+):(\d+)",
                    RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);

            try
            {
                var clientBootstrap = new ClientBootstrap()
                    .SetTransport(TransportType.Udp)
                    .OnConnect(ConnectionEstablishedCallback)
                    .OnReceive(ReceivedDataCallback)
                    .OnDisconnect(ConnectionTerminatedCallback)
                    .OnError(ConnectionOnOnError);
                _connectionFactory = clientBootstrap.Build();
            }
            catch (Exception)
            {

                throw;
            }
            _nodeDictionary = new Dictionary<string, INode>();
            _connectionDictionary = new Dictionary<string, IConnection>();
        }
Exemple #2
0
 static void Main(string[] args)
 {
     Console.WriteLine("We're going to write a ton of data to the console. 100k iterations.");
     Console.WriteLine("Going!");
     
     var remote = Node.Loopback(11010);
     var client =
         new ClientBootstrap().SetTransport(TransportType.Udp)
             .SetEncoder(new NoOpEncoder())
             .SetDecoder(new NoOpDecoder()).Build().NewConnection(Node.Any(), remote);
     client.Open();
     var bytes = Encoding.UTF8.GetBytes("THIS IS OUR TEST PAYLOAD");
     
     var stopwatch = Stopwatch.StartNew();
     var i = 0;
     while (i < 100000)
     {
         client.Send(bytes, 0, bytes.Length, remote);
         i++;
     }
     Console.WriteLine("Done queuing messages... waiting for queue to drain");
     while (client.MessagesInSendQueue > 0)
     {
         Thread.Sleep(10);
     }
     Console.WriteLine("Done, press any key to exit");
     stopwatch.Stop();
     Console.WriteLine("Took {0} seconds to complete", stopwatch.Elapsed.TotalSeconds);
     Console.ReadKey();
 }
Exemple #3
0
 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();
 }
Exemple #4
0
        static void Main(string[] args)
        {
            var host = IPAddress.Loopback;
            var port = 9991;
            var bootstrapper =
                new ClientBootstrap()
                    .SetTransport(TransportType.Tcp).Build();

            TimeClient = bootstrapper.NewConnection(Node.Empty(), NodeBuilder.BuildNode().Host(host).WithPort(port));
            TimeClient.OnConnection += (address, connection) =>
            {
                Console.WriteLine("Confirmed connection with host.");
                connection.BeginReceive(ReceivedCallback);
            };
            TimeClient.OnDisconnection += (address, reason) => Console.WriteLine("Disconnected.");

            Console.Title = string.Format("TimeClient {0}", Process.GetCurrentProcess().Id);
            LoopConnect();
            Console.WriteLine("Requesting time from server...");
            Console.WriteLine("Printing every 1/1000 received messages");
            LoopWrite();
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
 public TcpConnectionFactory(ClientBootstrap clientBootstrap) : base(clientBootstrap)
 {
 }
 protected ClientConnectionFactoryBase(ClientBootstrap clientBootstrap) : base(clientBootstrap) { }
Exemple #7
0
 protected ClientConnectionFactoryBase(ClientBootstrap clientBootstrap) : base(clientBootstrap)
 {
 }
Exemple #8
0
 public ClientBootstrap(ClientBootstrap other) : base(other)
 {
     Workers          = other.Workers;
     InternalExecutor = other.InternalExecutor;
 }
 public ClientBootstrap(ClientBootstrap other) : base(other)
 {
     Workers = other.Workers;
     InternalExecutor = other.InternalExecutor;
 }
 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;
     }
 }
 public TcpConnectionFactory(ClientBootstrap clientBootstrap) : base(clientBootstrap)
 {
 }