예제 #1
0
        public ServerSocket(IPEndPoint listeningEndPoint, SocketSetting setting, IBufferPool receiveDataBufferPool, Action <ITcpConnection, byte[], Action <byte[]> > messageArrivedHandler)
        {
            Ensure.NotNull(listeningEndPoint, "listeningEndPoint");
            Ensure.NotNull(setting, "setting");
            Ensure.NotNull(receiveDataBufferPool, "receiveDataBufferPool");
            Ensure.NotNull(messageArrivedHandler, "messageArrivedHandler");

            _listeningEndPoint        = listeningEndPoint;
            _setting                  = setting;
            _receiveDataBufferPool    = receiveDataBufferPool;
            _connectionEventListeners = new List <IConnectionEventListener>();
            _messageArrivedHandler    = messageArrivedHandler;
            _connectionDict           = new ConcurrentDictionary <Guid, ITcpConnection>();
            _socket                      = SocketUtils.CreateSocket(_setting.SendBufferSize, _setting.ReceiveBufferSize);
            _acceptSocketArgs            = new SocketAsyncEventArgs();
            _acceptSocketArgs.Completed += AcceptCompleted;
            _logger                      = null /* ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName)*/;
        }
예제 #2
0
        public ClientSocket(EndPoint serverEndPoint, EndPoint localEndPoint, SocketSetting setting, IBufferPool receiveDataBufferPool, Action <ITcpConnection, byte[]> messageArrivedHandler)
        {
            Ensure.NotNull(serverEndPoint, "serverEndPoint");
            Ensure.NotNull(setting, "setting");
            Ensure.NotNull(receiveDataBufferPool, "receiveDataBufferPool");
            Ensure.NotNull(messageArrivedHandler, "messageArrivedHandler");

            _connectionEventListeners = new List <IConnectionEventListener>();

            _serverEndPoint        = serverEndPoint;
            _localEndPoint         = localEndPoint;
            _setting               = setting;
            _receiveDataBufferPool = receiveDataBufferPool;
            _messageArrivedHandler = messageArrivedHandler;
            _waitConnectHandle     = new ManualResetEvent(false);
            _socket = SocketUtils.CreateSocket(_setting.SendBufferSize, _setting.ReceiveBufferSize);
            _logger = null /*ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName)*/;
            _flowControlThreshold = _setting.SendMessageFlowControlThreshold;
        }