コード例 #1
0
        private void OnClientConnected(Tcp connection, IPEndPoint endpoint, Loop loop)
        {
            try
            {
                var remoteEndPoint = connection.GetPeerEndPoint();       // get endpoint.
                var connectionId   = CorrelationIdGenerator.GetNextId(); // get an unique id for connection.
                _logger.Debug($"Accepting connection [{connectionId}] from {remoteEndPoint.Address}:{remoteEndPoint.Port}");

                connection.KeepAlive(true, 1); // allow keep-alive.

                var client = new StratumClient();

                client.Initialize(loop, connection, endpoint, connectionId,
                                  data => OnReceive(client, data),
                                  () => OnReceiveComplete(client),
                                  ex => OnReceiveError(client, ex));

                // register client
                lock (_clients)
                {
                    _clients[connectionId] = client;
                }

                _pool.OnConnect(client);
            }
            catch (Exception ex)
            {
                _logger.Error($"Client connection error: {ex.Message}");
            }
        }