コード例 #1
0
        /// <summary>
        /// Options for Engine.IO client.
        /// </summary>
        /// <param name="Scheme">Scheme to connect to.</param>
        /// <param name="Host">Host to connect to.</param>
        /// <param name="Port">Port to connect to.</param>
        /// <param name="PolicyPort">Port the policy server listens on.</param>
        /// <param name="Path">Path to connect to.</param>
        /// <param name="Query">Parameters that will be passed for each request to the server.</param>
        /// <param name="Upgrade">Whether the client should try to upgrade the transport.</param>
        /// <param name="RemeberUpgrade">Whether the client should bypass normal upgrade process when previous websocket connection is succeeded.</param>
        /// <param name="ForceBase64">Forces base 64 encoding for transport.</param>
        /// <param name="WithCredentials">Whether to include credentials such as cookies, authorization headers, TLS client certificates, etc. with polling requests.</param>
        /// <param name="TimestampRequests">Whether to add the timestamp with each transport request. Polling requests are always stamped.</param>
        /// <param name="TimestampParam">Timestamp parameter.</param>
        /// <param name="Polling">Whether to include polling transport.</param>
        /// <param name="PollingTimeout">Timeout for polling requests in milliseconds.</param>
        /// <param name="WebSocket">Whether to include websocket transport.</param>
        /// <param name="WebSocketSubprotocols">List of <see href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols">websocket subprotocols</see>.</param>
        /// <param name="ExtraHeaders">Headers that will be passed for each request to the server.</param>
        /// <param name="ClientCertificates">The collection of security certificates that are associated with each request.</param>
        /// <param name="ClientCertificateSelectionCallback">Callback used to select the certificate to supply to the server.</param>
        /// <param name="ServerCertificateValidationCallback">Callback method to validate the server certificate.</param>
        public EngineIOClientOption(EngineIOScheme Scheme, string Host, ushort Port, ushort PolicyPort = 843, string Path = "/engine.io", IDictionary <string, string> Query = null, bool Upgrade = true, bool RemeberUpgrade = false, bool ForceBase64 = false, bool WithCredentials = true, bool?TimestampRequests = null, string TimestampParam = "t", bool Polling = true, int PollingTimeout = 0, bool WebSocket = true, string[] WebSocketSubprotocols = null, IDictionary <string, string> ExtraHeaders = null, X509CertificateCollection ClientCertificates = null, LocalCertificateSelectionCallback ClientCertificateSelectionCallback = null, RemoteCertificateValidationCallback ServerCertificateValidationCallback = null)
        {
            this.Scheme     = Scheme;
            this.Host       = Host;
            this.Port       = Port;
            this.PolicyPort = PolicyPort;

            this.Path  = EngineIOOption.PolishPath(Path);
            this.Query = new Dictionary <string, string>(Query ?? new Dictionary <string, string>());

            this.Upgrade        = Upgrade;
            this.RemeberUpgrade = RemeberUpgrade;
            this.ForceBase64    = ForceBase64;

            this.WithCredentials   = WithCredentials;
            this.TimestampRequests = TimestampRequests;
            this.TimestampParam    = TimestampParam;

            this.Polling        = Polling;
            this.PollingTimeout = PollingTimeout;

            this.WebSocket             = WebSocket;
            this.WebSocketSubprotocols = WebSocketSubprotocols ?? new string[0];

            this.ExtraHeaders = new Dictionary <string, string>(ExtraHeaders ?? new Dictionary <string, string>());

            this.ClientCertificates = ClientCertificates;
            this.ClientCertificateSelectionCallback  = ClientCertificateSelectionCallback ?? DefaultClientCertificateSelectionCallback;
            this.ServerCertificateValidationCallback = ServerCertificateValidationCallback ?? EngineIOOption.DefaultCertificateValidationCallback;

            if (string.IsNullOrWhiteSpace(Host))
            {
                throw new ArgumentException("Host is not valid.", "Host");
            }

            if (!Polling && !WebSocket)
            {
                throw new ArgumentException("Either Polling or WebSocket must be used as transport.", "Polling, WebSocket");
            }

            if (!this.Query.ContainsKey("EIO"))
            {
                this.Query.Add("EIO", "3");
            }

            if (this.Query.ContainsKey("transport"))
            {
                this.Query.Remove("transport");
            }

            if (this.Query.ContainsKey("j"))
            {
                this.Query.Remove("j");
            }

            if (this.Query.ContainsKey("b64"))
            {
                this.Query.Remove("b64");
            }
        }
コード例 #2
0
        /// <summary>
        /// Options for Engine.IO server.
        /// </summary>
        /// <param name="Port">Port to listen.</param>
        /// <param name="Path">Path to listen.</param>
        /// <param name="Secure">Whether to secure connections.</param>
        /// <param name="PingTimeout">How many ms without a pong packet to consider the connection closed.</param>
        /// <param name="PingInterval">How many ms before sending a new ping packet.</param>
        /// <param name="UpgradeTimeout">How many ms before an uncompleted transport upgrade is cancelled.</param>
        /// <param name="Polling">Whether to accept polling transport.</param>
        /// <param name="WebSocket">Whether to accept websocket transport.</param>
        /// <param name="AllowUpgrade">Whether to allow transport upgrade.</param>
        /// <param name="SetCookie">Whether to use cookie.</param>
        /// <param name="SIDCookieName">Name of sid cookie.</param>
        /// <param name="Cookies">Configuration of the cookie that contains the client sid to send as part of handshake response headers. This cookie might be used for sticky-session.</param>
        /// <param name="AllowHttpRequest">A function that receives a given handshake or upgrade http request as its first parameter, and can decide whether to continue or not.</param>
        /// <param name="AllowWebSocket">A function that receives a given handshake or upgrade websocket connection as its first parameter, and can decide whether to continue or not.</param>
        /// <param name="InitialData">An optional packet which will be concatenated to the handshake packet emitted by Engine.IO.</param>
        /// <param name="ServerCertificate">The certificate used to authenticate the server.</param>
        /// <param name="ClientCertificateValidationCallback">Callback used to validate the certificate supplied by the client.</param>
        public EngineIOServerOption(ushort Port, string Path = "/engine.io", bool Secure = false, ulong PingTimeout = 5000, ulong PingInterval = 25000, ulong UpgradeTimeout = 10000, bool Polling = true, bool WebSocket = true, bool AllowUpgrade = true, bool SetCookie = true, string SIDCookieName = "io", IDictionary <string, string> Cookies = null, Action <HttpListenerRequest, Action <EngineIOException> > AllowHttpRequest = null, Action <WebSocketContext, Action <EngineIOException> > AllowWebSocket = null, object InitialData = null, X509Certificate2 ServerCertificate = null, RemoteCertificateValidationCallback ClientCertificateValidationCallback = null)
        {
            this.Port   = Port;
            this.Path   = EngineIOOption.PolishPath(Path);
            this.Secure = Secure;

            this.PingTimeout    = PingTimeout;
            this.PingInterval   = PingInterval;
            this.UpgradeTimeout = UpgradeTimeout;

            this.Polling      = Polling;
            this.WebSocket    = WebSocket;
            this.AllowUpgrade = AllowUpgrade;

            this.SetCookie     = SetCookie;
            this.SIDCookieName = SIDCookieName;
            this.Cookies       = new Dictionary <string, string>();

            this.AllowHttpRequest = AllowHttpRequest;
            this.AllowWebSocket   = AllowWebSocket;
            this.InitialData      = InitialData;

            this.ServerCertificate = ServerCertificate;
            this.ClientCertificateValidationCallback = ClientCertificateValidationCallback ?? EngineIOOption.DefaultCertificateValidationCallback;

            if (SetCookie)
            {
                this.Cookies["Path"]     = this.Path;
                this.Cookies["HttpOnly"] = "";
                this.Cookies["SameSite"] = "Lax";

                if (Cookies != null)
                {
                    foreach (string Key in Cookies.Keys)
                    {
                        this.Cookies[Key] = Cookies[Key] ?? this.Cookies[Key];
                    }
                }
            }
        }