public ClientSession(Socket socket) { _socket = socket; _sender = new TcpFrameSender(socket); _receiver = new TcpFrameReceiver(socket); _receiver.MessageReceived += message => MessageReceived?.Invoke(message); }
public void Stop() { if (!_isRunning) { return; } _isRunning = false; _receiver = null; _sender = null; _socket.Dispose(); _socket = null; }
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(); }