internal EndPointListener(IPEndPoint endpoint, bool secure, string certificateFolderPath, ServerSslConfiguration sslConfig, bool reuseAddress) { if (secure) { X509Certificate2 certificate = EndPointListener.getCertificate(endpoint.Port, certificateFolderPath, sslConfig.ServerCertificate); if (certificate == null) { throw new ArgumentException("No server certificate could be found."); } this._secure = true; this._sslConfig = new ServerSslConfiguration(certificate, sslConfig.ClientCertificateRequired, sslConfig.EnabledSslProtocols, sslConfig.CheckCertificateRevocation) { ClientCertificateValidationCallback = sslConfig.ClientCertificateValidationCallback }; } this._endpoint = endpoint; this._prefixes = new Dictionary <HttpListenerPrefix, WebSocketSharp.Net.HttpListener>(); this._unregistered = new Dictionary <HttpConnection, HttpConnection>(); this._unregisteredSync = ((ICollection)this._unregistered).SyncRoot; this._socket = new Socket(endpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (reuseAddress) { this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); } this._socket.Bind(endpoint); this._socket.Listen(500); this._socket.BeginAccept(new AsyncCallback(EndPointListener.onAccept), this); }
public EndPointListener(IPAddress address, int port, bool secure, string certFolderPath, X509Certificate2 defaultCert) { if (secure) { this._secure = secure; this._cert = EndPointListener.getCertificate(port, certFolderPath, defaultCert); if (this._cert == null) { throw new ArgumentException("Server certificate not found."); } } this._endpoint = new IPEndPoint(address, port); this._socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); this._socket.Bind(this._endpoint); this._socket.Listen(500); SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs(); socketAsyncEventArgs.UserToken = this; socketAsyncEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(EndPointListener.onAccept); this._socket.AcceptAsync(socketAsyncEventArgs); this._prefixes = new Dictionary <ListenerPrefix, HttpListener>(); this._unregistered = new Dictionary <HttpConnection, HttpConnection>(); }