示例#1
0
        public Client(IPEndPoint remoteEndPoint, BaseProtocol handler)
        {
            _remoteEndPoint = remoteEndPoint;
            _socket         = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            _bufferControl = new BufferControl(BufferSize, BufferSize);
            _bufferControl.Init();

            _protocol = handler;
        }
示例#2
0
        public Server(EndPoint localEndPoint, int numConnections, BaseProtocol handler)
        {
            _listenSocket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _listenSocket.Bind(localEndPoint);
            _listenSocket.Listen(100);

            _bufferControl            = new BufferControl(ReceiveBufferSize * numConnections, ReceiveBufferSize);
            _maxNumberAcceptedClients = new Semaphore(numConnections, numConnections);
            _sessions = new ConcurrentDictionary <uint, Session>();
            _bufferControl.Init();

            _protocol = handler;
        }