/// <summary> /// Configure <see cref="SocketListener"/> to use UDP. /// </summary> /// <param name="listenOptions">The <see cref="SocketListenerOptions"/> to configure.</param> public static SocketListenerOptions UseUdp(this SocketListenerOptions listenOptions) { if (listenOptions == null) { throw new ArgumentNullException(nameof(listenOptions)); } listenOptions.SocketType = SocketType.Dgram; listenOptions.ProtocolType = ProtocolType.Udp; return(listenOptions); }
/// <summary> /// Configure <see cref="SocketListener"/> to use TCP. /// </summary> /// <param name="listenOptions">The <see cref="SocketListenerOptions"/> to configure.</param> public static SocketListenerOptions UseTcp(this SocketListenerOptions listenOptions) { if (listenOptions == null) { throw new ArgumentNullException(nameof(listenOptions)); } listenOptions.SocketType = SocketType.Stream; listenOptions.ProtocolType = ProtocolType.Tcp; listenOptions.ReuseAddress = true; return(listenOptions); }
/// <summary> /// Bind to the given end point and configuration. /// </summary> /// <param name="endPoint">The endpoint for receiving data.</param> /// <param name="configure">The <see cref="SocketListener"/> configuration options features.</param> public void Listen(IPEndPoint endPoint, SocketListenerOptionsDelegate configure) { if (endPoint == null) { throw new ArgumentNullException(nameof(endPoint)); } var listenOptions = new SocketListenerOptions(endPoint); configure(listenOptions); Listener = listenOptions; }
/// <summary> /// Configure <see cref="SocketListener"/> to use HTTPS. /// </summary> /// <param name="listenOptions">The <see cref="SocketListenerOptions"/> to configure.</param> /// <param name="serverCertificate">The X.509 certificate.</param> public static SocketListenerOptions UseHttps(this SocketListenerOptions listenOptions, X509Certificate serverCertificate) { if (listenOptions == null) { throw new ArgumentNullException(nameof(listenOptions)); } if (serverCertificate == null) { throw new ArgumentNullException(nameof(serverCertificate)); } listenOptions.Certificate = serverCertificate; listenOptions.IsTls = true; listenOptions.KeepAlive = true; return(listenOptions); }