public bool Start(int Port) #endif { lock (this) { //keep this.Port = Port; //get certificate #if NETFX this._certificate = certificate; if (Certificate != null && !Certificate.HasPrivateKey) { DebugEx.Assert("Not private key found in servers certificate"); return(false); } #endif //create socket and bind try { #if NETFX sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Bind(new IPEndPoint(IPAddress.Any, Port)); #elif UNIVERSAL sock = new StreamSocketListener(); sock.ConnectionReceived += Sock_ConnectionReceived; sock.BindServiceNameAsync(Port.ToStringInvariant()).AsTask().Wait(); #endif } catch (Exception ex) { DebugEx.Assert(ex, "YPServer failed to bind port " + Port); return(false); } //mark running _IsRunning = true; //log #if NETFX DebugEx.TraceLog("YPServer (socks) started on port " + Port + " (Secure=" + (certificate != null).ToStringInvariant() + ")"); #elif UNIVERSAL DebugEx.TraceLog("YPServer (socks) started on port " + Port + " (Secure= False)"); #endif //start port listener #if NETFX PortListener = new Thread(PortListenerEntryPoint); PortListener.Name = "YPC Server PortListener thread"; PortListener.IsBackground = true; PortListener.Start(); #endif //done return(true); } }