public EndPointListener ( IPAddress address, int port, bool secure, string certificateFolderPath, ServerSslAuthConfiguration defaultCertificate, bool reuseAddress) { if (secure) { _secure = secure; _sslAuthenticationConfig = getCertificate(port, certificateFolderPath, defaultCertificate); if (_sslAuthenticationConfig == null) throw new ArgumentException ("No server certificate could be found."); } _prefixes = new Dictionary<HttpListenerPrefix, HttpListener> (); _unregistered = new Dictionary<HttpConnection, HttpConnection> (); _unregisteredSync = ((ICollection) _unregistered).SyncRoot; _socket = new Socket (address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (reuseAddress) _socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); _endpoint = new IPEndPoint (address, port); _socket.Bind (_endpoint); _socket.Listen (500); var args = new SocketAsyncEventArgs (); args.UserToken = this; args.Completed += onAccept; _socket.AcceptAsync (args); }
public EndPointListener( IPAddress address, int port, bool secure, string certificateFolderPath, ServerSslAuthConfiguration defaultCertificate, bool reuseAddress) { if (secure) { _secure = secure; _sslAuthenticationConfig = getCertificate(port, certificateFolderPath, defaultCertificate); if (_sslAuthenticationConfig == null) { throw new ArgumentException("No server certificate could be found."); } } _prefixes = new Dictionary <HttpListenerPrefix, HttpListener> (); _unregistered = new Dictionary <HttpConnection, HttpConnection> (); _unregisteredSync = ((ICollection)_unregistered).SyncRoot; _socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (reuseAddress) { _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); } _endpoint = new IPEndPoint(address, port); _socket.Bind(_endpoint); _socket.Listen(500); var args = new SocketAsyncEventArgs(); args.UserToken = this; args.Completed += onAccept; _socket.AcceptAsync(args); }
private static ServerSslAuthConfiguration getCertificate( int port, string certificateFolderPath, ServerSslAuthConfiguration defaultCertificate) { if (certificateFolderPath == null || certificateFolderPath.Length == 0) { certificateFolderPath = _defaultCertFolderPath; } try { var cer = Path.Combine(certificateFolderPath, String.Format("{0}.cer", port)); var key = Path.Combine(certificateFolderPath, String.Format("{0}.key", port)); if (File.Exists(cer) && File.Exists(key)) { var cert = new X509Certificate2(cer); cert.PrivateKey = createRSAFromFile(key); return(new ServerSslAuthConfiguration(cert)); } } catch { } return(defaultCertificate); }
private static ServerSslAuthConfiguration getCertificate( int port, string certificateFolderPath, ServerSslAuthConfiguration defaultCertificate) { if (certificateFolderPath == null || certificateFolderPath.Length == 0) certificateFolderPath = _defaultCertFolderPath; try { var cer = Path.Combine (certificateFolderPath, String.Format ("{0}.cer", port)); var key = Path.Combine (certificateFolderPath, String.Format ("{0}.key", port)); if (File.Exists (cer) && File.Exists (key)) { var cert = new X509Certificate2 (cer); cert.PrivateKey = createRSAFromFile (key); return new ServerSslAuthConfiguration(cert); } } catch { } return defaultCertificate; }