Пример #1
0
        private void ClientConnectedCallback(IAsyncResult ar)
        {
            if (!_running)
            {
                //listening for connections stopped
                _stopFinished.SetResult(1);
                return;
            }

            var tcpClient = _tcpListener.EndAcceptTcpClient(ar);

            log.Trace("incoming connection request");

            //prepare for next connect
            ListenForClients();

            //create socket and endpoint for new connection
            var socket   = new Socket();
            var endpoint = new Endpoint(socket);

            socket.Log = Logging.LogManager.GetLogger("Socket " + endpoint.Connection.Id);
            socket.SetTcpClient(tcpClient);
            log.Debug("connection request " + endpoint.Connection);

            //start endpoint message receiver
            endpoint.ReceiveThread = new Thread(() =>
            {
                ReceiveHandler(endpoint);
            });
            endpoint.ReceiveThread.Start();

            endpoint.Disconnected += Endpoint_Disconnected;

            _ = ConnectionHandler.ProcessEndpoint(endpoint.Connection, EndpointChangedEventArgs.NewConnection(endpoint));
        }
Пример #2
0
        private void ClientConnectedCallback(IAsyncResult ar)
        {
            if (!_running)
            {
                //listening for connections stopped
                _stopFinished.SetResult();
                return;
            }

            var tcpClient = _tcpListener.EndAcceptTcpClient(ar);

            log.Trace("incoming connection request");

            //prepare for next connect
            ListenForClients();

            //create socket and endpoint for new connection
            var socket   = new PacketSocket(tcpClient);
            var endpoint = new Endpoint(socket);

            log.Debug("connection request " + endpoint.Connection);

            var actionBlock = new ActionBlock <Tuple <IEndpoint, byte[]> >(ReceiveHandler);

            endpoint.MessageBlock.LinkTo(actionBlock);


            endpoint.Disconnected += Endpoint_Disconnected;

            _ = ConnectionHandler.ProcessEndpoint(endpoint.Connection, EndpointChangedEventArgs.NewConnection(endpoint));
        }