Тема: [C#] Network
Показать сообщение отдельно
Непрочитано 03.02.2017, 23:24   #2
Пользователь

По умолчанию Re: [C#] Network

Смотря подочто, если под L2 то я свою написал (асинхронный клиент\сервер)
Хотя подо что угодно можно поставить если учесть что в пакетах первые 2 байта будет размер пакета.(TCP)
для получения логов из библиотеки
Код:
Utils.Logger.InitLogger(OnLogMessage)

        private static void OnLogMessage(LogMessageType logMessageType, string message)
        {
            var biuldedMsg = new StringBuilder();

            switch (logMessageType)
            {
                case LogMessageType.Debug:
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(message);
                    break;
                case LogMessageType.Info:
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine(message);
                    break;
                case LogMessageType.Warning:
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine(message);
                    break;
                case LogMessageType.Error:
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine(message);
                    break;
                case LogMessageType.CriticalError:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(message);
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(logMessageType), logMessageType, null);
            }
        }
Ну а если не хотите шифровать трафик то просто реализуйте интерфейс ICrypt
таким образом.
Код:
using System;
using Utils.Interface;

namespace Utils.Crypt
{
    public sealed class NonCryptedCrypt: ICrypt
    {
        public bool Decrypt(ref byte[] data, int offset, int size)
        {
            return true;
        }

        public byte[] Encrypt(byte[] data, int offset, int size)
        {
            return data;
        }

        public void UpdateKey(byte[] key)
        {
            throw new NotImplementedException();
        }

        public byte[] GetKey()
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
и добавляйте его каждому новому соединению.

PS. нетти - прошлый век (обработка 5000+ соединений в 1 поток сомнительное решение)
при наличии у .net мощнейщего ThreadPool
ИМХО
Alay вне форума Ответить с цитированием
Сказали спасибо: