public TcpData(RxTcpClient client, byte[] data, EndPoint localEndPoint, EndPoint remoteEndPoint) { From = client; Data = data; LocalEndPoint = localEndPoint; RemoteEndPoint = remoteEndPoint; }
public TcpData(RxTcpClient client, byte[] data) { From = client; Data = data; }
private void AcceptCallback(IAsyncResult result) { if (Server == null) { return; } Socket client = null; try { client = Server.EndAccept(result); } catch (Exception exp) { _error.OnNext(new ErrorData("EndAccept", exp)); } if (client != null) { try { var rxClient = new RxTcpClient(client) { EnableKeepAlive = EnableKeepAlive, KeepAliveTime = KeepAliveTime, KeepAliveInterval = KeepAliveInterval, #if NETCORE3_0 KeepAliveRetryCount = KeepAliveRetryCount, #endif BufferSize = BufferSize // これだと初回が・・・ }; if (EnableKeepAlive) { rxClient.SetKeepAlive(); } // ↑の処理中にクライアントが切断されることがある if (rxClient.IsConnect) { var connectedClient = new ConnectedClient { Client = rxClient }; if (!_clients.TryAdd(connectedClient.Key, connectedClient)) { // ??? } Clients = new ReadOnlyCollection <RxTcpClient>(_clients.Values.Select(c => c.Client).ToList()); _accepted.OnNext(rxClient); // Notice connectedClient.Disposable.Add(rxClient.Closed.Subscribe(ClientClosed)); connectedClient.Disposable.Add(rxClient.Received.Subscribe(_received)); connectedClient.Disposable.Add(rxClient.Error.Subscribe(_error)); } } catch { } } StartAccept(); }