protected override void OnStart(string[] args)
        {
            try
            {
                string textProtocolIP = MemConfiguration.TextProtocolIP;
                int textPort = MemConfiguration.TextProtocolPort;
                string binaryProtocolIP = MemConfiguration.BinaryProtocolIP;
                int binaryPort = MemConfiguration.BinaryProtocolPort;

                if (textPort == binaryPort)
                {
                    throw new ArgumentException("Ports cannot be same for text and binary protocol.");
                }

                _tcpTextGateWay = new TcpNetworkGateway(textProtocolIP, textPort, Alachisoft.NCache.Integrations.Memcached.ProxyServer.NetworkGateway.ProtocolType.Text);
                _tcpTextGateWay.StartListenForClients();
                LogManager.Logger.Info("Proxy server for text protocol started at IP: " + textProtocolIP + " port: " + textPort);


                _tcpBinaryGateWay = new TcpNetworkGateway(binaryProtocolIP, binaryPort, Alachisoft.NCache.Integrations.Memcached.ProxyServer.NetworkGateway.ProtocolType.Binary);
                _tcpBinaryGateWay.StartListenForClients();
                LogManager.Logger.Info("Proxy server for binary protocol started at IP: " + binaryProtocolIP + " port: " + binaryPort);
            }
            catch (Exception e)
            {
                LogManager.Logger.Fatal("Service", "\t Failed to start proxy server. Exception : " + e);
                throw;
            }
        }
Exemple #2
0
        public void AsyncReadCallback(IAsyncResult ar)
        {
            try
            {
                int bytesRecieved = 0;

                if (_disposed)
                {
                    return;
                }
                try
                {
                    bytesRecieved = this._stream.EndRead(ar);
                }
                catch (ObjectDisposedException e)
                {
                    return;
                }

                if (bytesRecieved == 0)
                {
                    TcpNetworkGateway.DisposeClient(this);
                    return;
                }
                _inputDataStream.Write(_inputBuffer, 0, bytesRecieved);

                _stream.BeginRead(_inputBuffer, 0, MAX_BUFFER_SIZE, new AsyncCallback(AsyncReadCallback), null);

                lock (_parser)
                {
                    if (_parser.Alive)
                    {
                        return;
                    }
                    _parser.Alive = true;
                }
                _parser.StartParser();
            }
            catch (Exception e)
            {
                _logManager.Error("TcpClientHandler.AsyncReadCallback()", "\tError in client handler." + e.Message);
                TcpNetworkGateway.DisposeClient(this);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            try
            {
                string textProtocolIP = MemConfiguration.TextProtocolIP;
                int textPort = MemConfiguration.TextProtocolPort;
                string binaryProtocolIP = MemConfiguration.BinaryProtocolIP;
                int binaryPort = MemConfiguration.BinaryProtocolPort;

                if (textPort == binaryPort)
                {
                    throw new ArgumentException("Ports cannot be same for text and binary protocol.");
                }

                TcpNetworkGateway tcpTextGateWay = new TcpNetworkGateway(textProtocolIP, textPort, Alachisoft.NCache.Integrations.Memcached.ProxyServer.NetworkGateway.ProtocolType.Text);
                tcpTextGateWay.StartListenForClients();
                LogManager.Logger.Info("Proxy server for text protocol started at IP: " + textProtocolIP +  " port: " + textPort);

                TcpNetworkGateway tcpBinaryGateWay = new TcpNetworkGateway(binaryProtocolIP, binaryPort, Alachisoft.NCache.Integrations.Memcached.ProxyServer.NetworkGateway.ProtocolType.Binary);
                tcpBinaryGateWay.StartListenForClients();
                LogManager.Logger.Info("Proxy server for binary protocol started at IP: " +  binaryProtocolIP + " port: " + binaryPort);
            }
            catch (Exception e)
            {
                LogManager.Logger.Fatal("Service", "\t Failed to start proxy server. " + e.Message);
            }

            Console.WriteLine("Press Esc to exit.");
            ConsoleKey inputKey;
            do
            {
                inputKey = Console.ReadKey(false).Key;

            } while (inputKey != ConsoleKey.Escape);
            CacheFactory.DisposeCacheProvider();
        }