private void SetSocketAsConnected() { try { this.socketState = TcpSocketState.Connected; this.remoteIP = ((System.Net.IPEndPoint) this.tcpClient.Client.RemoteEndPoint).Address; if (this.useSsl) { //send test stream with: cat dump.pcap | socat - SSL:localhost:57012,verify=0 //socat GOPEN:dump.pcap SSL:localhost:57443,verify=0 System.Net.Security.SslStream sslStream = new System.Net.Security.SslStream(tcpClient.GetStream(), false); //sslStream.ReadTimeout = idleTimeoutMS; //8 seconds sslStream.AuthenticateAsServer(ServerCert.Instance, false, System.Security.Authentication.SslProtocols.Default, false); this.pcapStream = sslStream; } else { this.pcapStream = this.tcpClient.GetStream(); } this.pcapStream.ReadTimeout = this.idleTimeoutMS; //this.tcpClient.ReceiveTimeout = this.idleTimeoutMS;//not required, we do stream.ReadTimeout instead } catch { this.Dispose(); } }
public PcapTcpStream(ushort localTcpPort, bool useSsl, int idleTimeoutMilliSeconds) : this(useSsl, idleTimeoutMilliSeconds) { this.socketState = TcpSocketState.Closed; this.tcpListener = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, (int)localTcpPort); tcpListener.Start(); this.socketState = TcpSocketState.Listening; }
public void Dispose() { this.socketState = TcpSocketState.Closed; if (this.pcapStream != null) { try { this.pcapStream.Close(); } catch { } this.pcapStream.Dispose(); } this.pcapStream = null; if (this.tcpClient != null) { this.tcpClient.Close(); } if (this.tcpListener != null) { try { this.tcpListener.Stop(); } catch { } //this.tcpListener = null; } }
public void Connect(IPAddress ipAddress, int port) { if (socketState != TcpSocketState.Connecting) { socketState = TcpSocketState.Connecting; socket.Connect(ipAddress, port); socketState = TcpSocketState.Idle; //socket.BeginConnect(ipAddress, port, new AsyncCallback(ConnectCallback), null); StartReceivingLoop(); } }
public PcapTcpStream(string remoteIpOrHost, ushort remotePort, bool useSSl, int idleTimeoutMilliSeconds, System.Windows.Forms.MethodInvoker streamEstablishedHandler) : this(useSSl, idleTimeoutMilliSeconds) { this.tcpClient = new TcpClient(remoteIpOrHost, remotePort); if (this.tcpClient.Connected) { this.SetSocketAsConnected(); //streamEstablishedHandler. .DynamicInvoke(); } else { this.socketState = TcpSocketState.Closed; } }
public void Connect(string ipAddressOrHostname, int port) { if (socketState == TcpSocketState.Idle) { // Get host related information. IPHostEntry hostEntry = Dns.GetHostEntry(ipAddressOrHostname); socketState = TcpSocketState.Connecting; // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid // an exception that occurs when the host host IP Address is not compatible with the address family // (typical in the IPv6 case). TryNextTempSocketConnection(hostEntry.AddressList, 0, port); } }
private void TempSocketConnectComplete() { socketState = TcpSocketState.Idle; }
private void ConnectCallback(IAsyncResult result) { // We are connected! socket.EndConnect(result); socketState = TcpSocketState.Idle; }
public void Connect(IPAddress ipAddress, int port) { if (socketState != TcpSocketState.Connecting) { socketState = TcpSocketState.Connecting; socket.Connect(ipAddress, port); socketState = TcpSocketState.Idle; //socket.BeginConnect(ipAddress, port, new AsyncCallback(ConnectCallback), null); StartReceivingLoop(); } }
public void Connect(string ipAddressOrHostname, int port) { if (socketState == TcpSocketState.Idle) { // Get host related information. IPHostEntry hostEntry = Dns.GetHostEntry(ipAddressOrHostname); socketState = TcpSocketState.Connecting; // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid // an exception that occurs when the host host IP Address is not compatible with the address family // (typical in the IPv6 case). TryNextTempSocketConnection(hostEntry.AddressList, 0, port); } }
private void ConnectCallback(IAsyncResult result) { // We are connected! socket.EndConnect(result); socketState = TcpSocketState.Idle; }
private void TempSocketConnectComplete() { socketState = TcpSocketState.Idle; }