Exemple #1
0
        private void ListenerThread()
        {
            m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            m_Socket.Bind(m_Binding);
            m_Socket.Listen(5);
            Socket new_connection = null;

            do
            {
                new_connection = null;
                try {
                    new_connection = m_Socket.Accept();
                }
                catch (SocketException) {
                }
                if (new_connection == null)
                {
                    break;
                }
                if (NewConnectionEvent != null)
                {
                    NewConnectionEvent.Invoke(this, new NewConnectionEventArgs(new_connection));
                }
                else
                {
                    new_connection.Close();
                }
            } while(true);
            m_Socket = null;

            if (CloseEvent != null)
            {
                CloseEvent.Invoke(this, new ListenerCloseEventArgs());
            }
        }
Exemple #2
0
        /// <summary>
        /// Method called for a new connection
        /// </summary>
        /// <param name="graph">The new connection graph</param>
        private void OnNewConnection(NetGraph graph)
        {
            bool connAdded = false;

            lock (_connections)
            {
                if (_state == (int)ServiceState.Running)
                {
                    _connections.Add(new ConnectionEntry(this, graph, _defaultTimeout, _afterData));
                    connAdded = true;
                }
            }

            if (connAdded)
            {
                NewConnectionEvent?.Invoke(this, new ConnectionEventArgs(graph));

                if (_logger != null)
                {
                    _logger.LogVerbose(CANAPE.Net.Properties.Resources.NetworkServiceBase_ConnectionEstablished,
                                       graph.NetworkDescription);
                }
            }
            else
            {
                // We are not running don't add it, just kill
                try
                {
                    ((IDisposable)graph).Dispose();
                }
                catch
                {
                }
            }
        }
Exemple #3
0
        private void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            StreamSocket streamSocket = args.Socket;

            Connection connection = new Connection(this, streamSocket);

            NewConnectionEvent?.Invoke(null, new NewConnectionArguments(
                                           connection
                                           ));
        }
        public void OnNewConnectionHandler(object sender, IConnector connector)
        {
            if (connector == null)
            {
                return;
            }
            lock (_cSync){
                if (_connectors.Count > _maxCount)
                {
                    connector.Disconnect(); return;
                }
                _connectors.Add(connector.UniqueID, connector);
            }
            connector.DisconnectEvent  += OnConnectorDisconnectHandler;
            connector.ReceiveAction    += OnReceveDataHandler;
            connector.ReceiveComAction += OnReceiveCommandHandler;

            NewConnectionEvent?.Invoke(this, connector);
        }
        private async Task PollAsync(Socket socket, int microSeconds)
        {
            try {
                if (socket.Poll(microSeconds, SelectMode.SelectRead))
                {
                    Socket remote = await socket.AcceptAsync().ConfigureAwait(false);

                    Logger.Info($"New connection from {remote.RemoteEndPoint}");

                    NewConnectionEvent?.Invoke(this, new NewConnectionEventArgs
                    {
                        Socket = remote
                    }
                                               );
                }
            } catch (SocketException e) {
                Logger.Error("Exception polling sockets!", e);
            }
        }
Exemple #6
0
 private void service_NewConnectionEvent(object sender, ConnectionEventArgs e)
 {
     NewConnectionEvent?.Invoke(sender, e);
 }
Exemple #7
0
 public ConnectionController(NewConnectionEvent eventHandler)
 {
     newConnectionEventHandler = eventHandler;
     commands = new ConcurrentQueue <Command>();
     clients  = new ConcurrentDictionary <string, SoftwareIncClient>();
 }