Exemplo n.º 1
0
        private async Task AcceptLoopAsync(ISocketConfiguration socketConfiguration, CancellationToken cancellationToken, NodeType nodeType)
        {
            _started.Set();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var tcpClient = await _listener.AcceptTcpClientAsync();

                    SetupTcpClientParametersWithoutReceiveTimeout(tcpClient, socketConfiguration);
                    tcpClient.ReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType) ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0;

                    var socket = new TcpSocket(_endpoint, tcpClient);
                    socket.Disconnected += () => ClientDisconnected(socket);

                    TryFireClientConnectedEvent(socket, socketConfiguration);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (OperationCanceledException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
            finally
            {
                _stopped.Set();
            }
        }
Exemplo n.º 2
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
            {
                throw new InvalidOperationException("Server already bound, please use Unbind first");
            }

            var ipAddress = IpAddressFromHostTranslator.GetIpAddressForHost(endpoint.Host);

            _endpoint = endpoint;

            _listener = new TcpListener(ipAddress, endpoint.Port);

            if (onClientConnected != null)
            {
                ClientConnected += onClientConnected;
            }
            if (onClientDisconnected != null)
            {
                ClientDisconnected += onClientDisconnected;
            }

            _stopped.Reset();
            _started.Reset();

            _listener.Start();

            _cts = new CancellationTokenSource();

            StartAcceptLoop(socketConfiguration, _cts.Token, nodeType);
        }
Exemplo n.º 3
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            var remoteNodeType = NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            switch (remoteNodeType)
            {
            case NodeType.ServiceQueueReader:
                ReaderClientConnected(socket, socketConfiguration);
                break;

            case NodeType.ServiceQueueWriter:
                WriterClientConnected(socket, socketConfiguration);
                break;

            default:
                throw new RedFoxProtocolException(String.Format("Unsupported node type connected to ServiceQueue: {0}", remoteNodeType));
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                CheckIfSocketDisconnected(socket);
            }
        }
Exemplo n.º 4
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);
            var messageQueue       = new MessageQueueBatch(socketConfiguration.SendBufferSize);
            var messageReceiveLoop = new MessageReceiveLoop(_messageSerialization, socket, OnMessageReceived, MessageReceiveLoopOnException);

            if (_broadcastSockets.TryAdd(socket, new MessageQueueReceiveLoop(messageQueue, messageReceiveLoop)))
            {
                _messageQueueBroadcaster.Register(messageQueue, messageFrameWriter);
                ClientConnected(socket, socketConfiguration);
                messageReceiveLoop.Start();
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                SocketDisconnected(socket);
            }
        }
Exemplo n.º 5
0
        private async Task AcceptLoopAsync(ISocketConfiguration socketConfiguration, CancellationToken cancellationToken, NodeType nodeType)
        {
            _started.Set();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var tcpClient = await _listener.AcceptTcpClientAsync();
                    SetupTcpClientParametersWithoutReceiveTimeout(tcpClient, socketConfiguration);
                    tcpClient.ReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType) ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0;

                    var socket = new TcpSocket(_endpoint, tcpClient);
                    socket.Disconnected += () => ClientDisconnected(socket);

                    TryFireClientConnectedEvent(socket, socketConfiguration);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (OperationCanceledException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
            finally
            {
                _stopped.Set();
            }
        }
Exemplo n.º 6
0
        public void Connect(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
        {
            if (socketConfiguration == null)
            {
                throw new ArgumentNullException("socketConfiguration");
            }
            if (_socket != null)
            {
                throw new InvalidOperationException("Subscriber already connected");
            }
            _cts = new CancellationTokenSource();

            _socket = SocketFactory.CreateAndConnectAsync(endpoint, NodeType.Subscriber, socketConfiguration);
            _socket.Disconnected += SocketDisconnected;

            NodeGreetingMessageVerifier.SendReceiveAndVerify(_socket, socketConfiguration.ConnectTimeout);

            if (!_cts.IsCancellationRequested)
            {
                _messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(_socket);

                _messageReceiveLoop = new MessageReceiveLoop(_messageSerialization, _socket, OnMessageReceived, MessageReceiveLoopOnException);
                _messageReceiveLoop.Start();
            }
        }
Exemplo n.º 7
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            var messageFrameWriter   = MessageFrameWriterFactory.CreateWriterFromSocket(socket);
            var messageFrameReceiver = new MessageFrameReceiver(socket);
            var senderReceiver       = new SenderReceiver(messageFrameWriter, messageFrameReceiver);

            socket.Disconnected += () => SocketDisconnected(socket);

            if (_clientSockets.TryAdd(socket, senderReceiver))
            {
                var task = ReceiveRequestMessage(senderReceiver);
                ClientConnected(socket, socketConfiguration);
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                SocketDisconnected(socket);
            }
        }
Exemplo n.º 8
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
                throw new InvalidOperationException("Server already bound, please use Unbind first");

            var ipAddress = IpAddressFromHostTranslator.GetIpAddressForHost(endpoint.Host);

            _endpoint = endpoint;

            _listener = new TcpListener(ipAddress, endpoint.Port);

            if (onClientConnected != null)
                ClientConnected += onClientConnected;
            if (onClientDisconnected != null)
                ClientDisconnected += onClientDisconnected;

            _stopped.Reset();
            _started.Reset();

            _listener.Start();

            _cts = new CancellationTokenSource();

            StartAcceptLoop(socketConfiguration, _cts.Token, nodeType);
        }
Exemplo n.º 9
0
        private void ReaderClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);

            if (_readerClientSockets.TryAdd(socket, messageFrameWriter))
            {
                _messageQueueDistributor.Register(messageFrameWriter);

                ClientConnected(socket, socketConfiguration);
            }
        }
Exemplo n.º 10
0
 public ISocket CreateAndConnectAsync(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration)
 {
     switch (endpoint.Transport)
     {
         case RedFoxTransport.Inproc:
             return CreateInProcSocket(endpoint);
         case RedFoxTransport.Tcp:
             return CreateTcpSocket(endpoint, nodeType, socketConfiguration);
         default:
             throw new NotSupportedException(String.Format("Transport {0} not supported", endpoint.Transport));
     }
 }
Exemplo n.º 11
0
        private void WriterClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            var messageFrameReceiver = new MessageFrameReceiver(socket);

            messageFrameReceiver.Disconnected += () => WriterSocketDisconnected(socket);
            var task = ReceiveAsync(messageFrameReceiver, _disposedToken);

            if (_writerClientSockets.TryAdd(socket, messageFrameReceiver))
            {
                ClientConnected(socket, socketConfiguration);
            }
        }
Exemplo n.º 12
0
        public ISocketAccepter CreateAndBind(RedFoxEndpoint endpoint,
            NodeType nodeType,
            ISocketConfiguration socketConfiguration,
            ClientConnectedDelegate onClientConnected = null,
            ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (socketConfiguration == null) throw new ArgumentNullException("socketConfiguration");

            var server = CreateForTransport(endpoint.Transport);
            server.Bind(endpoint, nodeType, socketConfiguration, onClientConnected, onClientDisconnected);
            return server;
        }
Exemplo n.º 13
0
 private bool TryFireClientConnectedEvent(ISocket socket, ISocketConfiguration socketConfiguration)
 {
     try
     {
         ClientConnected(socket, socketConfiguration);
         return(true);
     }
     catch
     {
         // TODO: log exception somewhere
         return(false);
     }
 }
Exemplo n.º 14
0
 private bool TryFireClientConnectedEvent(InProcSocket socket, ISocketConfiguration socketConfiguration)
 {
     try
     {
         socket.Disconnected += () => ClientDisconnected(socket);
         ClientConnected(socket, socketConfiguration);
         return true;
     }
     catch
     {
         return false;
     }
 }
 private bool TryFireClientConnectedEvent(InProcSocket socket, ISocketConfiguration socketConfiguration)
 {
     try
     {
         socket.Disconnected += () => ClientDisconnected(socket);
         ClientConnected(socket, socketConfiguration);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 16
0
 public SocketBase(ISocketConfiguration configuration)
 {
     _configuration = configuration;
     if (configuration.Autoconnect)
     {
         CyclicExecutor.Instance.Add(_cycleId, _cycleId, 5000, () =>
         {
             CyclicExecutor.Instance.Enabled(_cycleId, false);
             if (!IsConnected && !_shutdown)
             {
                 Open();
             }
         });
     }
 }
Exemplo n.º 17
0
        public void Connect(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
        {
            if (socketConfiguration == null) throw new ArgumentNullException("socketConfiguration");
            if (_socket != null) throw new InvalidOperationException("Subscriber already connected");
            _cts = new CancellationTokenSource();

            _socket = SocketFactory.CreateAndConnectAsync(endpoint, NodeType.ServiceQueueWriter, socketConfiguration);
            _socket.Disconnected += SocketDisconnected;

            NodeGreetingMessageVerifier.SendReceiveAndVerify(_socket, socketConfiguration.ConnectTimeout);

            if (!_cts.IsCancellationRequested)
            {
                _messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(_socket);
            }
        }
Exemplo n.º 18
0
        public ISocketAccepter CreateAndBind(RedFoxEndpoint endpoint,
                                             NodeType nodeType,
                                             ISocketConfiguration socketConfiguration,
                                             ClientConnectedDelegate onClientConnected       = null,
                                             ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (socketConfiguration == null)
            {
                throw new ArgumentNullException("socketConfiguration");
            }

            var server = CreateForTransport(endpoint.Transport);

            server.Bind(endpoint, nodeType, socketConfiguration, onClientConnected, onClientDisconnected);
            return(server);
        }
Exemplo n.º 19
0
        private static ISocket CreateTcpSocket(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration)
        {
            var hasReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType);

            var tcpClient = new TcpClient
            {
                ReceiveTimeout = hasReceiveTimeout ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0,
                SendTimeout = socketConfiguration.SendTimeout.ToMillisOrZero(),

                NoDelay = true,
                ReceiveBufferSize = socketConfiguration.ReceiveBufferSize,
                SendBufferSize = socketConfiguration.SendBufferSize
            };
            ConnectTcpSocket(tcpClient, endpoint.Host, endpoint.Port, socketConfiguration.ConnectTimeout);

            return new TcpSocket(endpoint, tcpClient);
        }
Exemplo n.º 20
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
                throw new InvalidOperationException("Server already bound, please use Unbind first");

            _listener = InProcessEndpoints.Instance.RegisterAccepter(endpoint);
            _endpoint = endpoint;

            if (onClientConnected != null)
                ClientConnected += onClientConnected;
            if (onClientDisconnected != null)
                ClientDisconnected += onClientDisconnected;

            _started.Reset();
            _cts = new CancellationTokenSource();
            Task.Factory.StartNew(() => StartAcceptLoop(_cts.Token, socketConfiguration), TaskCreationOptions.LongRunning);
            _started.Wait();
        }
        private void StartAcceptLoop(CancellationToken cancellationToken, ISocketConfiguration socketConfiguration)
        {
            _stopped.Reset();
            _started.Set();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var socketPair = _listener.Take(cancellationToken);
                    TryFireClientConnectedEvent(socketPair.ServerSocket, socketConfiguration);
                }
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                _stopped.Set();
            }
        }
Exemplo n.º 22
0
        private void StartAcceptLoop(CancellationToken cancellationToken, ISocketConfiguration socketConfiguration)
        {
            _stopped.Reset();
            _started.Set();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var socketPair = _listener.Take(cancellationToken);
                    TryFireClientConnectedEvent(socketPair.ServerSocket, socketConfiguration);
                }
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                _stopped.Set();
            }
        }
Exemplo n.º 23
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null) throw new ArgumentNullException("socket");

            var remoteNodeType = NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);
            switch (remoteNodeType)
            {
                case NodeType.ServiceQueueReader:
                    ReaderClientConnected(socket, socketConfiguration);
                    break;
                case NodeType.ServiceQueueWriter:
                    WriterClientConnected(socket, socketConfiguration);
                    break;
                default:
                    throw new RedFoxProtocolException(String.Format("Unsupported node type connected to ServiceQueue: {0}", remoteNodeType));
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                CheckIfSocketDisconnected(socket);
            }
        }
Exemplo n.º 24
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null) throw new ArgumentNullException("socket");

            NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);
            var messageQueue = new MessageQueueBatch(socketConfiguration.SendBufferSize);
            var messageReceiveLoop = new MessageReceiveLoop(_messageSerialization, socket, OnMessageReceived, MessageReceiveLoopOnException);

            if (_broadcastSockets.TryAdd(socket, new MessageQueueReceiveLoop(messageQueue, messageReceiveLoop)))
            {
                _messageQueueBroadcaster.Register(messageQueue, messageFrameWriter);
                ClientConnected(socket, socketConfiguration);
                messageReceiveLoop.Start();
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                SocketDisconnected(socket);
            }
        }
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
            {
                throw new InvalidOperationException("Server already bound, please use Unbind first");
            }

            _listener = InProcessEndpoints.Instance.RegisterAccepter(endpoint);
            _endpoint = endpoint;

            if (onClientConnected != null)
            {
                ClientConnected += onClientConnected;
            }
            if (onClientDisconnected != null)
            {
                ClientDisconnected += onClientDisconnected;
            }

            _started.Reset();
            _cts = new CancellationTokenSource();
            Task.Factory.StartNew(() => StartAcceptLoop(_cts.Token, socketConfiguration), TaskCreationOptions.LongRunning);
            _started.Wait();
        }
Exemplo n.º 26
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null) throw new ArgumentNullException("socket");

            NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);
            var messageFrameReceiver = new MessageFrameReceiver(socket);
            var senderReceiver = new SenderReceiver(messageFrameWriter, messageFrameReceiver);

            socket.Disconnected += () => SocketDisconnected(socket);

            if (_clientSockets.TryAdd(socket, senderReceiver))
            {
                var task = ReceiveRequestMessage(senderReceiver);
                ClientConnected(socket, socketConfiguration);
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                SocketDisconnected(socket);
            }
        }
Exemplo n.º 27
0
 public void Bind(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
 {
     var server = SocketAccepterFactory.CreateAndBind(endpoint, NodeType.Responder, socketConfiguration, OnClientConnected);
     _servers[endpoint] = server;
 }
Exemplo n.º 28
0
        public void Bind(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
        {
            var server = SocketAccepterFactory.CreateAndBind(endpoint, NodeType.Responder, socketConfiguration, OnClientConnected);

            _servers[endpoint] = server;
        }
Exemplo n.º 29
0
        private void ReaderClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);

            if (_readerClientSockets.TryAdd(socket, messageFrameWriter))
            {
                _messageQueueDistributor.Register(messageFrameWriter);

                ClientConnected(socket, socketConfiguration);
            }
        }
Exemplo n.º 30
0
        private static void SetupTcpClientParametersWithoutReceiveTimeout(TcpClient tcpClient, ISocketConfiguration socketConfiguration)
        {
            tcpClient.SendTimeout = socketConfiguration.SendTimeout.ToMillisOrZero();

            tcpClient.NoDelay = true;
            tcpClient.ReceiveBufferSize = socketConfiguration.ReceiveBufferSize;
            tcpClient.SendBufferSize = socketConfiguration.SendBufferSize;
        }
Exemplo n.º 31
0
 private bool TryFireClientConnectedEvent(ISocket socket, ISocketConfiguration socketConfiguration)
 {
     try
     {
         ClientConnected(socket, socketConfiguration);
         return true;
     }
     catch
     {
         // TODO: log exception somewhere
         return false;
     }
 }
Exemplo n.º 32
0
        public ISocket CreateAndConnectAsync(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration)
        {
            switch (endpoint.Transport)
            {
            case RedFoxTransport.Inproc:
                return(CreateInProcSocket(endpoint));

            case RedFoxTransport.Tcp:
                return(CreateTcpSocket(endpoint, nodeType, socketConfiguration));

            default:
                throw new NotSupportedException(String.Format("Transport {0} not supported", endpoint.Transport));
            }
        }
Exemplo n.º 33
0
 private void StartAcceptLoop(ISocketConfiguration socketConfiguration, CancellationToken cancellationToken, NodeType nodeType)
 {
     var task = AcceptLoopAsync(socketConfiguration, cancellationToken, nodeType);
 }
Exemplo n.º 34
0
 public void Bind(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
 {
     var server = SocketAccepterFactory.CreateAndBind(endpoint, NodeType.ServiceQueue, socketConfiguration, OnClientConnected, CheckIfSocketDisconnected);
     _servers[endpoint] = server;
 }
Exemplo n.º 35
0
 public SocketBase(ISocketConfiguration configuration)
 {
     _configuration = configuration;
 }
Exemplo n.º 36
0
        public void Bind(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
        {
            var server = SocketAccepterFactory.CreateAndBind(endpoint, NodeType.ServiceQueue, socketConfiguration, OnClientConnected, CheckIfSocketDisconnected);

            _servers[endpoint] = server;
        }
Exemplo n.º 37
0
 private void StartAcceptLoop(ISocketConfiguration socketConfiguration, CancellationToken cancellationToken, NodeType nodeType)
 {
     var task = AcceptLoopAsync(socketConfiguration, cancellationToken, nodeType);
 }
Exemplo n.º 38
0
        private static void SetupTcpClientParametersWithoutReceiveTimeout(TcpClient tcpClient, ISocketConfiguration socketConfiguration)
        {
            tcpClient.SendTimeout = socketConfiguration.SendTimeout.ToMillisOrZero();

            tcpClient.NoDelay           = true;
            tcpClient.ReceiveBufferSize = socketConfiguration.ReceiveBufferSize;
            tcpClient.SendBufferSize    = socketConfiguration.SendBufferSize;
        }
Exemplo n.º 39
0
        private static ISocket CreateTcpSocket(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration)
        {
            var hasReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType);

            var tcpClient = new TcpClient
            {
                ReceiveTimeout = hasReceiveTimeout ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0,
                SendTimeout    = socketConfiguration.SendTimeout.ToMillisOrZero(),

                NoDelay           = true,
                ReceiveBufferSize = socketConfiguration.ReceiveBufferSize,
                SendBufferSize    = socketConfiguration.SendBufferSize
            };

            ConnectTcpSocket(tcpClient, endpoint.Host, endpoint.Port, socketConfiguration.ConnectTimeout);

            return(new TcpSocket(endpoint, tcpClient));
        }
Exemplo n.º 40
0
        private void WriterClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            var messageFrameReceiver = new MessageFrameReceiver(socket);
            messageFrameReceiver.Disconnected += () => WriterSocketDisconnected(socket);
            var task = ReceiveAsync(messageFrameReceiver, _disposedToken);

            if (_writerClientSockets.TryAdd(socket, messageFrameReceiver))
            {
                ClientConnected(socket, socketConfiguration);
            }
        }