private void DetectTcpCsSocketIncomingConnection(uint hresult, SecureTunnelListener listener, SecureTunnel tunnel) { if (this.TcpCsSocketIncomingTunnels.Contains(tunnel)) { return; } if (hresult != 0) { Debug.Log("CsSocketTcp Incoming Connection Exception HResult: " + hresult); return; } Debug.Log("CsSocketTcp Incoming Connection to our port " + tunnel.LocalPort + ": " + tunnel.State + "," + tunnel.RemoteHostName.CanonicalName + ":" + tunnel.RemotePort); tunnel.OnStateChanged += StateChanged; // Notify us if the state of this connection changes this.TcpCsSocketIncomingTunnels.Add(tunnel); }
public override void StartServer() { if (string.IsNullOrEmpty(strLocalSda) == true) { strLocalSda = localSda.ToString(); // Convert the SDA to a base64 string for easy display and transport } Debug.Log("Local Device Address: " + strLocalSda); File.WriteAllText(outputPath + "serverSDA.txt", strLocalSda); this.tcpListener = new TcpListener(IPAddress.IPv6Any, port); this.tcpListener.Server.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0); // MANDATORY - Allow incoming IPv4 packets (which includes Teredo-wrapped IPv4 packets) this.tcpListener.Start(); this.tcpListener.BeginAcceptSocket(new AsyncCallback(this.DataReceivedTCP), this.tcpListener); this.TcpCsSocketDetectIncoming = new SecureTunnelListener("TcpCsSocketServer"); this.TcpCsSocketDetectIncoming.OnIncomingSecureTunnel += this.DetectTcpCsSocketIncomingConnection; }