async Task Connect(string host, int port) { await ConnectAsync(host, port); _pump = new FramePump(_client.GetStream()); _outboundEndpoint = new OutboundTcpEndpoint(this, _pump); _inboundEndpoint = _rpcEngine.AddEndpoint(_outboundEndpoint); _pumpThread = new Thread(() => { try { Thread.CurrentThread.Name = $"TCP RPC Client Thread {Thread.CurrentThread.ManagedThreadId}"; _pump.Run(); } finally { _outboundEndpoint.Dismiss(); _inboundEndpoint.Dismiss(); _pump.Dispose(); } }); _pump.FrameReceived += _inboundEndpoint.Forward; _pumpThread.Start(); }
public Connection(TcpRpcServer server, TcpClient client, FramePump pump, OutboundTcpEndpoint outboundEp, RpcEngine.RpcEndpoint inboundEp) { Client = client; Pump = pump; OutboundEp = outboundEp; InboundEp = inboundEp; PumpRunner = new Thread(o => { try { Thread.CurrentThread.Name = $"TCP RPC Server Thread {Thread.CurrentThread.ManagedThreadId}"; Pump.Run(); } finally { OutboundEp.Dismiss(); InboundEp.Dismiss(); Pump.Dispose(); lock (server._reentrancyBlocker) { --server.ConnectionCount; server._connections.Remove(this); } } }); }