public SocketRemotingClient(string address, int port)
 {
     _address = address;
     _port = port;
     _clientSocket = new ClientSocket();
     _responseFutureDict = new ConcurrentDictionary<long, ResponseFuture>();
     _responseMessageQueue = new BlockingCollection<byte[]>(new ConcurrentQueue<byte[]>());
     _scheduleService = ObjectContainer.Resolve<IScheduleService>();
     _processResponseMessageWorker = new Worker(ProcessResponseMessage);
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().Name);
     _clientSocket.Connect(address, port);
 }
        public SocketRemotingClient(EndPoint serverEndPoint, EndPoint localEndPoint = null)
        {
            _serverEndPoint = serverEndPoint;
            _localEndPoint = localEndPoint;
            _clientSocket = new ClientSocket(serverEndPoint, localEndPoint, ReceiveReplyMessage);
            _responseFutureDict = new ConcurrentDictionary<long, ResponseFuture>();
            _replyMessageQueue = new BlockingCollection<byte[]>(new ConcurrentQueue<byte[]>());
            _responseHandlerDict = new Dictionary<int, IResponseHandler>();
            _connectionEventListeners = new List<IConnectionEventListener>();
            _scheduleService = ObjectContainer.Resolve<IScheduleService>();
            _worker = new Worker("SocketRemotingClient.HandleReplyMessage", HandleReplyMessage);
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);

            RegisterConnectionEventListener(new ConnectionEventListener(this));
        }
示例#3
0
        public SocketRemotingClient(EndPoint serverEndPoint, SocketSetting setting = null, EndPoint localEndPoint = null)
        {
            Ensure.NotNull(serverEndPoint, "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 = ObjectContainer.Resolve<IScheduleService>();
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);

            RegisterConnectionEventListener(new ConnectionEventListener(this));
        }
示例#4
0
        private void ReconnectServer()
        {
            _logger.InfoFormat("Try to reconnect to server, address: {0}", _serverEndPoint);

            if (_clientSocket.IsConnected) return;
            if (!EnterReconnecting()) return;

            try
            {
                _clientSocket.Shutdown();
                _clientSocket = new ClientSocket(_serverEndPoint, _localEndPoint, _setting, _receiveDataBufferPool, HandleReplyMessage);
                foreach (var listener in _connectionEventListeners)
                {
                    _clientSocket.RegisterConnectionEventListener(listener);
                }
                _clientSocket.Start(2000);
            }
            catch (Exception ex)
            {
                _logger.Error("Reconnect to server error.", ex);
                ExitReconnecting();
            }
        }