public void ConnectToUnknownHostShouldTimeOut() { using (var client = new TcpSocket()) { bool isTimedOut = false; client.Connect(ServerAddress, 12345, () => isTimedOut = true); Assert.IsFalse(isTimedOut); Thread.Sleep(3500); Assert.IsTrue(isTimedOut); } }
private void AcceptCallback(IAsyncResult asyncResult) { lock (this) { if (!IsListening) return; Socket clientHandle = nativeSocket.EndAccept(asyncResult); var newConnectedClient = new TcpSocket(clientHandle); TriggerClientConnectedEvent(newConnectedClient); newConnectedClient.WaitForData(); nativeSocket.BeginAccept(AcceptCallback, null); } }
private void AcceptCallback(IAsyncResult asyncResult) { lock (this) { if (!IsListening) { return; } Socket clientHandle = nativeSocket.EndAccept(asyncResult); var newConnectedClient = new TcpSocket(clientHandle); TriggerClientConnectedEvent(newConnectedClient); newConnectedClient.WaitForData(); nativeSocket.BeginAccept(AcceptCallback, null); } }
private void TriggerClientConnectedEvent(TcpSocket newConnectedClient) { if (ClientConnected != null) ClientConnected(newConnectedClient); }
private static Client CreatedConnectedClient() { var client = new TcpSocket(); client.Connect(ServerAddress, serverPort); return client; }
private void ConnectToServer() { connection = new TcpSocket(); connection.Connect(ServerAddress, ServerPort); }