Exemplo n.º 1
0
        private void ProcessReceiveCompletedHandle()
        {
            WebSocketOpcode opcode;

            while (true)
            {
                var code = PacketData(ref Buffer, ref NStream, out opcode);

                switch (code)
                {
                case ParsePacketInternalCode.HasNextData:
                {
                    continue;
                }

                case ParsePacketInternalCode.NotAllData:
                {
                    return;
                }

                case ParsePacketInternalCode.Success:
                {
                    switch (opcode)
                    {
                    case WebSocketOpcode.Text:
                        break;

                    case WebSocketOpcode.Binary:
                    {
                        var databuffer = NStream?.ToArray();
                        this.webSocketSession?.OnMessageComing(new WebSocketSessionMessageComingArg(databuffer)
                                {
                                    Opcode = opcode,
                                    Count  = databuffer.Length,
                                    Offset = 0
                                });
                        break;
                    }

                    case WebSocketOpcode.Ping:
                    {
                        SendData(WebSocketOpcode.Pong);
                        break;
                    }

                    case WebSocketOpcode.Pong:
                    {
                        continue;
                    }

                    case WebSocketOpcode.Close:
                    {
                        SendData(WebSocketOpcode.Close);
                        this.Dispose();
                        return;
                    }

                    case WebSocketOpcode.Unkonown:
                        break;

                    case WebSocketOpcode.Go:
                        break;

                    default:
                    {
                        SendData(WebSocketOpcode.Close);
                        this.Dispose();
                        return;
                    }
                    }
                    continue;
                }

                default:
                {
                    SendData(WebSocketOpcode.Close);
                    this.Dispose();
                    return;
                }
                }
            }
        }