예제 #1
0
            public ClientSession(Socket socket)
            {
                _socket = socket;

                _sender   = new TcpFrameSender(socket);
                _receiver = new TcpFrameReceiver(socket);
                _receiver.MessageReceived += message => MessageReceived?.Invoke(message);
            }
예제 #2
0
        public void Stop()
        {
            if (!_isRunning)
            {
                return;
            }

            _isRunning = false;

            _receiver = null;
            _sender   = null;

            _socket.Dispose();
            _socket = null;
        }
예제 #3
0
        public void Start(string peerId)
        {
            if (_isRunning)
            {
                throw new InvalidOperationException("Already started");
            }

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            {
                NoDelay = true
            };

            _socket.Connect(_serverEndpoint);

            _sender   = new TcpFrameSender(_socket);
            _receiver = new TcpFrameReceiver(_socket);
            _receiver.MessageReceived += OnMessageReceived;

            _isRunning = true;

            _receiver.StartReceive();

            Connected?.Invoke();
        }