public ListenSocket(Socket socket, TcpServerLocalEndpoint tcpServerLocalEndpoint) { _socket = socket; TcpServerLocalEndpoint = tcpServerLocalEndpoint; _acceptedE = new ManualResetEvent(false); AcceptBegin = false; }
void ConnectionTest(TcpServerLocalEndpoint tslep) { List <TcpClient> clientsList = new List <TcpClient>(); TcpClient client; for (int i = 0; i < tslep.MaxClients; i++) { client = new TcpClient(); client.ConnectionFailEvent += Client_ConnectionFailEvent; client.DisconnectedEvent += Client_DisconnectedEvent; clientsList.Add(client); ServerConnectedEventArgs = null; ConnectionFailEventArgs = null; //ServerDisconnectedEventArgs = null; Assert.IsNull(ServerConnectedEventArgs); Assert.IsNull(ConnectionFailEventArgs); //Assert.IsNull(ServerDisconnectedEventArgs); client.Start(tslep.EndPoint); Thread.Sleep(200); Assert.IsNull(ConnectionFailEventArgs); Assert.IsNotNull(ServerConnectedEventArgs); //Assert.IsNull(ServerDisconnectedEventArgs); Assert.AreEqual(tslep.EndPoint, ServerConnectedEventArgs.LocalEndPoint); } client = new TcpClient(); client.ConnectionFailEvent += Client_ConnectionFailEvent; client.DisconnectedEvent += Client_DisconnectedEvent; clientsList.Add(client); ServerConnectedEventArgs = null; ConnectionFailEventArgs = null; ClientDisconnectedEventColled = false; Assert.IsNull(ServerConnectedEventArgs); Assert.IsNull(ConnectionFailEventArgs); Assert.IsFalse(ClientDisconnectedEventColled); client.Start(tslep.EndPoint); Thread.Sleep(400); Assert.IsNull(ServerConnectedEventArgs); Assert.IsTrue(ConnectionFailEventArgs != null || ClientDisconnectedEventColled); foreach (TcpClient tcpClient in clientsList) { tcpClient.Dispose(); } clientsList.Clear(); }
void ConnectionTest(TcpServerLocalEndpoint tslep, string serverName, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, EncryptionPolicy encryptionPolicy) { List <TcpClient> clientsList = new List <TcpClient>(); List <X509Certificate> clientsCerts = new List <X509Certificate>(); X509Certificate clientCert; TcpClient client; for (int i = 0; i < tslep.MaxClients; i++) { clientCert = MakeCert(serverName); clientsCerts.Add(clientCert); client = new TcpClient(); client.ConnectionFailEvent += Client_ConnectionFailEvent; client.DisconnectedEvent += Client_DisconnectedEvent; clientsList.Add(client); ServerConnectedEventArgs = null; ConnectionFailEventArgs = null; //ServerDisconnectedEventArgs = null; Assert.IsNull(ServerConnectedEventArgs); Assert.IsNull(ConnectionFailEventArgs); //Assert.IsNull(ServerDisconnectedEventArgs); client.Start(tslep.EndPoint, serverName, clientCert, enabledSslProtocols, checkCertificateRevocation, encryptionPolicy); Thread.Sleep(200); Assert.IsNull(ConnectionFailEventArgs); Assert.IsNotNull(ServerConnectedEventArgs); //Assert.IsNull(ServerDisconnectedEventArgs); Assert.AreEqual(tslep.EndPoint, ServerConnectedEventArgs.LocalEndPoint); } clientCert = MakeCert(serverName); clientsCerts.Add(clientCert); client = new TcpClient(); client.ConnectionFailEvent += Client_ConnectionFailEvent; client.DisconnectedEvent += Client_DisconnectedEvent; clientsList.Add(client); ServerConnectedEventArgs = null; ConnectionFailEventArgs = null; ClientDisconnectedEventColled = false; Assert.IsNull(ServerConnectedEventArgs); Assert.IsNull(ConnectionFailEventArgs); Assert.IsFalse(ClientDisconnectedEventColled); client.Start(tslep.EndPoint, serverName, clientCert, enabledSslProtocols, checkCertificateRevocation, encryptionPolicy); Thread.Sleep(400); Assert.IsNull(ServerConnectedEventArgs); Assert.IsTrue(ConnectionFailEventArgs != null || ClientDisconnectedEventColled); foreach (TcpClient tcpClient in clientsList) { tcpClient.Dispose(); } clientsList.Clear(); foreach (X509Certificate cert in clientsCerts) { cert.Dispose(); } clientsCerts.Clear(); }