Example #1
0
        public SocketRemotingClient(EndPoint serverEndPoint, SocketSetting setting = null, EndPoint localEndPoint = null)
        {
            serverEndPoint.CheckNotNull("serverEndPoint");

            _serverEndPoint           = serverEndPoint;
            _localEndPoint            = localEndPoint;
            _setting                  = setting ?? new SocketSetting();
            _receiveDataBufferPool    = new BufferPool(_setting.ReceiveDataBufferSize, _setting.ReceiveDataBufferPoolSize);
            _clientSocket             = new ClientSocket(_serverEndPoint, _localEndPoint, _setting, _receiveDataBufferPool, HandleReplyMessage);
            _responseFutureDict       = new ConcurrentDictionary <long, ResponseFuture>();
            _replyMessageQueue        = new BlockingCollection <byte[]>(new ConcurrentQueue <byte[]>());
            _responseHandlerDict      = new Dictionary <int, IResponseHandler>();
            _connectionEventListeners = new List <IConnectionEventListener>();
            _scheduleService          = IocManager.Instance.Resolve <IScheduleService>();
            _logger = IocManager.Instance.Resolve <ILoggerFactory>().Create(GetType().FullName);

            RegisterConnectionEventListener(new ConnectionEventListener(this));
        }
Example #2
0
        public ClientSocket(EndPoint serverEndPoint, EndPoint localEndPoint, SocketSetting setting, IBufferPool receiveDataBufferPool, Action <ITcpConnection, byte[]> messageArrivedHandler)
        {
            serverEndPoint.CheckNotNull("serverEndPoint");
            setting.CheckNotNull("setting");
            receiveDataBufferPool.CheckNotNull("receiveDataBufferPool");
            messageArrivedHandler.CheckNotNull("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 = IocManager.Instance.Resolve <ILoggerFactory>().Create(GetType().FullName);
            _flowControlThreshold = _setting.SendMessageFlowControlThreshold;
        }
Example #3
0
 public static string ToAddress(this EndPoint endpoint)
 {
     endpoint.CheckNotNull("endpoint");
     return(((IPEndPoint)endpoint).ToAddress());
 }