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

            if (handShaker.HandShake() <= 0)
            {
                Stop();
            }

            wsl            = new WSListener(client.GetStream());
            wsl.OnStarted += wsl_OnStarted;
            wsl.OnSinglePacketReceived     += wsl_SinglePacketReceived;
            wsl.OnFragmentReceived         += wsl_FragmentReceived;
            wsl.OnFragmentedPacketReceived += 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, ByteManager.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();
        }