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


C# WebSocket.GetAvailableProcessor方法代码示例

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


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


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