当前位置: 首页>>代码示例>>C#>>正文


C# WebSocket.FireError方法代码示例

本文整理汇总了C#中WebSocket.FireError方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocket.FireError方法的具体用法?C# WebSocket.FireError怎么用?C# WebSocket.FireError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebSocket的用法示例。


在下文中一共展示了WebSocket.FireError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteCommand

        public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
        {
            var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

            commandInfo.Text.ParseMimeHeader(dict);

            string websocketVersion = dict.GetValue(m_WebSocketVersion, string.Empty);

            if (!session.NotSpecifiedVersion)
            {
                if (string.IsNullOrEmpty(websocketVersion))
                    session.FireError(new Exception("the server doesn't support the websocket protocol version your client was using"));
                else
                    session.FireError(new Exception(string.Format("the server(version: {0}) doesn't support the websocket protocol version your client was using", websocketVersion)));
                session.CloseWithoutHandshake();
                return;
            }

            if (string.IsNullOrEmpty(websocketVersion))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            var versions = websocketVersion.Split(',');

            versions = versions.Where((x) => x.Trim().Length > 0).ToArray();

            var versionValues = new int[versions.Length];

            for (var i = 0; i < versions.Length; i++)
            {
                try
                {
                    int value = int.Parse(versions[i]);
                    versionValues[i] = value;
                }
                catch (FormatException)
                {
                    session.FireError(new Exception("invalid websocket version"));
                    session.CloseWithoutHandshake();
                    return;
                }
            }

            if (!session.GetAvailableProcessor(versionValues))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            session.ProtocolProcessor.SendHandshake(session);
        }
开发者ID:xsIceman,项目名称:WebSocket4Net,代码行数:55,代码来源:BadRequest.cs

示例2: ExecuteCommand

        public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
        {
            var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            var verbLine = string.Empty;

            commandInfo.Text.ParseMimeHeader(dict, out verbLine);

            string websocketVersion = dict.GetValue(m_WebSocketVersion, string.Empty);

            if (!session.NotSpecifiedVersion)
            {
                if (string.IsNullOrEmpty(websocketVersion))
                    session.FireError(new Exception("the server doesn't support the websocket protocol version your client was using"));
                else
                    session.FireError(new Exception(string.Format("the server(version: {0}) doesn't support the websocket protocol version your client was using", websocketVersion)));
                session.CloseWithoutHandshake();
                return;
            }

            if (string.IsNullOrEmpty(websocketVersion))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            var versions = websocketVersion.Split(m_ValueSeparator, StringSplitOptions.RemoveEmptyEntries);

            var versionValues = new int[versions.Length];

            for (var i = 0; i < versions.Length; i++)
            {
                int value;

                if (!int.TryParse(versions[i], out value))
                {
                    session.FireError(new Exception("invalid websocket version"));
                    session.CloseWithoutHandshake();
                    return;
                }

                versionValues[i] = value;
            }

            if (!session.GetAvailableProcessor(versionValues))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            session.ProtocolProcessor.SendHandshake(session);
        }
开发者ID:kengoemon,项目名称:WebSocket4Net,代码行数:53,代码来源:BadRequest.cs

示例3: ExecuteCommand

        public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
        {
            string description;

            if (!session.ProtocolProcessor.VerifyHandshake(session, commandInfo, out description))
            {
                session.FireError(new Exception(description));
                session.Close(session.ProtocolProcessor.CloseStatusCode.ProtocolError, description);
                return;
            }

            session.OnHandshaked();
        }
开发者ID:kengoemon,项目名称:WebSocket4Net,代码行数:13,代码来源:Handshake.cs

示例4: ExecuteCommand

        public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
        {
            //Close handshake was sent from client side, now got a handshake response
            if (session.State == WebSocketState.Closing)
            {
                //Not NormalClosure
                if (commandInfo.CloseStatusCode != session.ProtocolProcessor.CloseStatusCode.NormalClosure &&
                    (commandInfo.CloseStatusCode > 0 || !string.IsNullOrEmpty(commandInfo.Text)))
                {
                    session.FireError(new Exception(string.Format("{0}: {1}", commandInfo.CloseStatusCode, commandInfo.Text)));
                }
                session.CloseWithouHandshake();
                return;
            }

            //Got server side closing handshake request, send response now
            var statusCode = commandInfo.CloseStatusCode;

            if (statusCode <= 0)
                statusCode = session.ProtocolProcessor.CloseStatusCode.NoStatusCode;

            session.Close(statusCode, commandInfo.Text);
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:23,代码来源:Close.cs


注:本文中的WebSocket.FireError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。