示例#1
0
        public void Start()
        {
            Consoler.WriteLine("Client #{0} connected!", ConsoleColor.White, uid);

            HandShake();

            wsl = new WSListener(client.GetStream());
            wsl.SinglePacketReceived     += wsl_SinglePacketReceived;
            wsl.FragmentReceived         += wsl_FragmentReceived;
            wsl.FragmentedPacketReceived += wsl_FragmentedPacketReceived;
            wsl.Start();
        }
示例#2
0
        private void ReceivingHandler(int uid, WSPacket packet, string header)
        {
            dataTotalLength += (uint)packet.Data.Length;
            traffic         += (uint)packet.HeadersLength;
            ConsoleColor clr = Console.ForegroundColor;

            switch (uid)
            {
            case 0: clr = ConsoleColor.Cyan;
                break;

            case 1: clr = ConsoleColor.Yellow;
                break;

            case 2: clr = ConsoleColor.Blue;
                break;
            }
            Consoler.WriteLine(header, clr);
            switch (packet.Opcode)
            {
            case 1:
                Consoler.WriteLine(byteArrayToString(packet.Data));
                break;

            case 2:
                Consoler.WriteLine("Получены бинарные данные!", ConsoleColor.Magenta);
                break;

            case 8:
                Consoler.WriteLine("Соединение закрыто удаленной стороной! Код причины: {0}", ConsoleColor.Magenta, WSListener.Int16FromBytes(packet.Data[0], packet.Data[1]));
                Stop();
                break;

            case 9:
                Consoler.WriteLine("Получен пакет 'PING'!", ConsoleColor.Magenta);
                break;

            case 10:
                Consoler.WriteLine("Получен пакет 'PONG'!", ConsoleColor.Magenta);
                break;
            }
            Consoler.WriteLine();
        }