Exemple #1
0
        public TcpServerTest()
        {
            _server = new RxTcpServer();

            _server.Error.Subscribe(e => Log.AddOnScheduler($"Error.{e.Method} - {e.Exception?.Message}"));
            _server.Accepted.Subscribe(e => Log.AddOnScheduler($"Accept. from {e.Client.RemoteEndPoint}"));
            _server.Closed.Subscribe(e => Log.AddOnScheduler($"Closed.{e}"));
            _server.Received.Subscribe(e => Log.AddOnScheduler($"Receive (from {e.From.Client.RemoteEndPoint}).\n{e.Data.ToDumpString()}"));

            Listen.Subscribe(_ =>
            {
                try
                {
                    _server.Listen(Address.Value, Port.Value);
                    Log.Add($"Listen {Address.Value} : {Port.Value}");
                }
                catch (Exception exp)
                {
                    Log.Add($"Listen error.{exp.Message}");
                }
            });

            Close.Subscribe(_ => _server.Close());

            this.Broadcast.Subscribe(data => _server.Broadcast(data.ToSendData()));
        }
Exemple #2
0
        public UdpListenerTest()
        {
            _listener = new RxUdpListener();
            _listener.Received.Subscribe(e => Log.AddOnScheduler($"Receive (from {e.From}).\n{e.Data.ToDumpString()}"));

            Listen.Subscribe(_ =>
            {
                try
                {
                    if (Multicast.Value)
                    {
                        _listener.Listen(Address.Value, Port.Value);
                    }
                    else
                    {
                        _listener.Listen(Port.Value);
                    }
                    Log.Add($"Listen {(Multicast.Value ? Address.Value + " : " : "")}{Port.Value}");
                }
                catch (Exception exp)
                {
                    Log.Add($"Listen error.{exp.Message}");
                }
            });

            Close.Subscribe(_ => _listener.Close());
        }