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


C# Connection.PromptToSend方法代码示例

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


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

示例1: GracefulShutdown

 protected override void GracefulShutdown(NetContext context, Connection connection)
 {
     connection.DisableRead();
     var ws = (WebSocketConnection) connection;
     if(ws.HasSentClose)
     {
         ws.HasSentClose = true;
         SendData(context, new BinaryFrame(new byte[] {0xFF, 0x00}, true));
     }
     SendShutdown(context);
     connection.PromptToSend(context);
 }
开发者ID:mpotra,项目名称:NetGain,代码行数:12,代码来源:WebSocketsProcessor_Hixie76_00.cs

示例2: CompleteHandshake

        protected internal override void CompleteHandshake(NetContext context, Connection connection, Stream input, string requestLine, StringDictionary headers, byte[] body)
        {


            string key = headers["Sec-WebSocket-Key"];
            if(key != null) key = key.Trim();
            string response = ComputeReply(context, key);

            var builder = new StringBuilder(
                              "HTTP/1.1 101 Switching Protocols\r\n"
                            + "Upgrade: websocket\r\n"
                            + "Connection: Upgrade\r\n"
                            + "Sec-WebSocket-Accept: ").Append(response).Append("\r\n");

            var wc = connection as WebSocketConnection;
            var extn = wc == null ? null : wc.Extensions;
            if (extn != null)
            {
                List<string> extnHeaders = null;
                for (int i = 0; i < extn.Length; i++)
                {
                    string extnHeader = extn[i].GetResponseHeader();
                    if (!string.IsNullOrEmpty(extnHeader))
                    {
                        if (extnHeaders == null) extnHeaders = new List<string>();
                        extnHeaders.Add(extnHeader);
                    }
                }
                if (extnHeaders != null)
                {
                    builder.Append("Sec-WebSocket-Extensions: ").Append(extnHeaders[0]);
                    for (int i = 1; i < extnHeaders.Count; i++)
                        builder.Append(", ").Append(extnHeaders[i]);
                    builder.Append("\r\n");
                }
            }

            builder.Append("\r\n");
            SendControl(context, new StringFrame(builder.ToString(), Encoding.ASCII));
            connection.PromptToSend(context);
        }
开发者ID:mpotra,项目名称:NetGain,代码行数:41,代码来源:WebSocketsProcessor_RFC6455_13.cs

示例3: ProcessFrame

        private void ProcessFrame(NetContext context, Connection connection, WebSocketsFrame frame)
        {
            if(IsClient)
            {
                if(frame.Mask.HasValue) throw new InvalidOperationException("Clients only expect unmasked frames");
            } else
            {
                if (!frame.Mask.HasValue) throw new InvalidOperationException("Servers only expect masked frames");
            }
            var ws = (WebSocketConnection) connection;
            if(frame.IsControlFrame)
            {
                if(!frame.IsFinal) throw new InvalidOperationException("control frames cannot be fragmented");
                switch(frame.OpCode)
                {
                    case WebSocketsFrame.OpCodes.Close:
                        // respond with a closing handshake
                        GracefulShutdown(context, connection);
                        break;
                    case WebSocketsFrame.OpCodes.Pong:
                        // could add some reaction here
                        break;
                    case WebSocketsFrame.OpCodes.Ping:
                        // send a "pong" with the same payload
                        var pong = new WebSocketsFrame();
                        if (IsClient) pong.Mask = CreateMask();
                        pong.OpCode = WebSocketsFrame.OpCodes.Binary;
                        pong.PayloadLength = frame.PayloadLength;
                        if(frame.Payload != null)
                        {
                            var ms = new MemoryStream((int)frame.Payload.Length);
                            byte[] buffer = null;
                            try
                            {
                                buffer = context.GetBuffer();
                                Copy(frame.Payload, ms, buffer, null, frame.PayloadLength);
                            } finally
                            {
                                context.Recycle(buffer);
                            }
                            pong.Payload = ms;
                        }
                        SendControl(context, pong);
                        connection.PromptToSend(context);
                        break;
                    default:
                        throw new InvalidOperationException();
                }
            }
            else
            {
                if (!ws.AllowIncomingDataFrames) throw new InvalidOperationException("Data frames disabled");

                int pendingCount = FrameCount;
                if (frame.OpCode == WebSocketsFrame.OpCodes.Continuation)
                {
                    if(pendingCount == 0) throw new InvalidOperationException("Continuation of nothing");
                }
                else  if (pendingCount != 0)
                {
                    throw new InvalidOperationException("Should be a continuation");
                }
                if (!frame.IsFinal)
                {
                    Push(context, frame);
                }
                else
                {
                    if(pendingCount == 0)
                    {
                        Process(context, connection, frame.Payload, frame.OpCode);
                    } else
                    {
                        throw new NotImplementedException();
                    }
                }

            }
            if (frame.OpCode == WebSocketsFrame.OpCodes.Close)
            {
                Debug.WriteLine("Sent close frame: " + connection);
            }
        }
开发者ID:mpotra,项目名称:NetGain,代码行数:83,代码来源:WebSocketsProcessor_RFC6455_13.cs

示例4: GracefulShutdown

 protected override void GracefulShutdown(NetContext context, Connection connection)
 {
     connection.DisableRead();
     var ws = (WebSocketConnection) connection;
     if(!ws.HasSentClose)
     {
         ws.HasSentClose = true;
         var close = new WebSocketsFrame();
         if (IsClient) close.Mask = CreateMask();
         close.OpCode = WebSocketsFrame.OpCodes.Close;
         close.PayloadLength = 0;
         SendControl(context, close);
     }
     SendShutdown(context);
     connection.PromptToSend(context);
 }
开发者ID:mpotra,项目名称:NetGain,代码行数:16,代码来源:WebSocketsProcessor_RFC6455_13.cs

示例5: CompleteHandshake

 protected internal override void CompleteHandshake(NetContext context, Connection connection, System.IO.Stream input, string requestLine, System.Collections.Specialized.StringDictionary headers, byte[] body)
 {
     keys = Tuple.Create(headers["Sec-WebSocket-Key1"], headers["Sec-WebSocket-Key2"]);
     var builder = new StringBuilder(
         "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
         + "Upgrade: WebSocket\r\n"
         + "Connection: Upgrade\r\n");
     var conn = (WebSocketConnection)connection;
     if (!string.IsNullOrEmpty(conn.Host))
     { // we should add the origin/location, but that depends on what we have available to us
         builder.Append("Sec-WebSocket-Origin: ").Append(conn.Origin).Append("\r\n");
         if (!string.IsNullOrEmpty(conn.RequestLine))
         {
             Match match;
             if ((match = Regex.Match(conn.RequestLine, @"GET ([^\s]+) HTTP")).Success)
             {
                 builder.Append("Sec-WebSocket-Location: ").Append("ws://").Append(conn.Host).Append(match.Groups[1].Value).Append("\r\n");
             }
         }
     }
     if (!string.IsNullOrEmpty(conn.Protocol))
         builder.Append("Sec-WebSocket-Protocol: ").Append(conn.Protocol).Append("\r\n");
     builder.Append("\r\n");
     SendControl(context, new StringFrame(builder.ToString(), Encoding.ASCII, false));
     connection.PromptToSend(context);
 }
开发者ID:mpotra,项目名称:NetGain,代码行数:26,代码来源:WebSocketsProcessor_Hixie76_00.cs

示例6: ProcessIncoming

            protected override int ProcessIncoming(NetContext context, Connection connection, Stream incoming)
            {
                if (keys != null) // handshake is not yet complete
                {
                    if (incoming.Length < 8) return 0; // need 8 bytes to finish the handshake

                    var key3 = new byte[8];
                    NetContext.Fill(incoming, key3, 8);

                    // now that we're on a different protocol, send the server's response to the client's challenge
                    var securityCheck = ComputeKey(keys.Item1, keys.Item2, key3);
                    keys = null; // wipe
                    SendControl(context, new BinaryFrame(securityCheck));
                    connection.PromptToSend(context);
                    return 8;
                }
                return base.ProcessIncoming(context, connection, incoming);
            }
开发者ID:mpotra,项目名称:NetGain,代码行数:18,代码来源:WebSocketsProcessor_Hixie76_00.cs


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