Beispiel #1
0
        public override void Run()
        {
            try
            {
                while (true)
                {
                    try
                    {
                        var clientSocket = _serverSocket.Accept();
                        if (_connectionCount == _maxConnections)
                        {
                            clientSocket.Close();
                            continue;
                        }

                        var handler = new ConnectionHandler(clientSocket, _settings, _newAsduEvent, _pubSubHub);
                        handler.Start();
                        _connectionCount++;
                    }
                    catch (IOException e)
                    {
                        _pubSubHub.Publish <Exception>(this, "error", e);
                    }
                    catch (Exception e)
                    {
                        _pubSubHub.Publish(this, "error", e);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Abort();
            }
        }
Beispiel #2
0
        public override void Run()
        {
            _connection = new Connection(_socket, _settings);
            _connection.ConnectionClosed += e => { _pubSubHub.Publish <Exception>(this, "error", e); };

            _connection.NewASdu += _newAsduEvent;

            _connection.WaitForStartDT(5000);
        }
Beispiel #3
0
        public ConnectionHandler(Socket socket, ConnectionSettings settings,
                                 ConnectionEventListener.NewASdu newASduEvent, PubSubHub pubSubHub)
        {
            _socket       = socket;
            _settings     = settings;
            _newAsduEvent = newASduEvent;
            _pubSubHub    = pubSubHub;

            _pubSubHub.Subscribe <ASdu>(this, "send", asdu =>
            {
                try
                {
                    _connection.Send(asdu);
                }
                catch (Exception e)
                {
                    _pubSubHub.Publish(this, "error", e);
                }
            });
        }
Beispiel #4
0
 public void SendASdu(ASdu asdu)
 {
     _pubSubHub.Publish(this, "send", asdu);
 }