Exemple #1
0
        public void Start()
        {
            try
            {
                _currentSessions = new List<Session>();

                // Initialize and start server which accepts tracker connections
                var socketListener = new SocketListener(NetworkSettings.GetFromAppConfig());
                socketListener.ActiveChannels.CollectionChanged += ActiveSessions_CollectionChanged;

                // Initialize and start Node interface (used by other services to access devices realtime)
                // Processor
                var implementation = new NodeServiceImplementation(_currentSessions);
                var testProcessor = new NodeService.Processor(implementation);

                // Transport
                // todo: define port in AppConfig!
                var tServerSocket = new TServerSocket(4445, 0, true);

                // ThreadPool Server
                TServer serverEngine = new TThreadPoolServer(testProcessor, tServerSocket);

                // Run it
                serverEngine.Serve();

                Console.WriteLine("Server is running...press any key to exit...");

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Exemple #2
0
 static void Main()
 {
     var processor = new AccountService.Processor(new AccountServiceHandler());
     var transport = new TServerSocket(18801);
     var server = new TThreadPoolServer(processor, transport);
     server.Serve();
 }
Exemple #3
0
        public void Run()
        {
            log.InfoFormat("Starting master service on port {0}.", options.Port);

            TServerTransport transport = null;
            try
            {
                lock (syncRoot)
                {
                    if (stopped)
                        return;

                    var handler = new MasterServiceHandler();
                    var processor = new VMToolMaster.Processor(handler);
                    transport = new TServerSocket(options.Port);
                    server = new TThreadPoolServer(processor, transport, message => log.Error(message));
                }

                server.Serve();
                server = null;
            }
            finally
            {
                if (server != null)
                    server.Stop();
                if (transport != null)
                    transport.Close();
            }
        }
        static void Execute(int port)
        {
            try
            {
                // create protocol factory, default to BinaryProtocol
                TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true);
                TServerTransport servertrans = new TServerSocket(port, 0, false);
                TTransportFactory TransportFactory = new TFramedTransport.Factory();

                BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl();
                TProcessor benchProcessor = new BenchmarkService.Processor(benchHandler);

                Aggr.Iface aggrHandler = new AggrServiceImpl();
                TProcessor aggrProcessor = new Aggr.Processor(aggrHandler);

                TMultiplexedProcessor multiplex = new TMultiplexedProcessor();
                multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor);
                multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor);

                TServer ServerEngine = new TSimpleServer(multiplex, servertrans, TransportFactory, ProtocolFactory);

                Console.WriteLine("Starting the server ...");
                ServerEngine.Serve();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            Log.Use().SimpleConsoleColored();

            Log.Information("Booting");

            try
            {
                int port = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["Interface.Port"]);

                InterfaceNodeHandler handler = new InterfaceNodeHandler();

                InterfaceNodeService.Processor processor = new InterfaceNodeService.Processor(handler);
                TServerTransport serverTransport = new TServerSocket(port);
                TServer server = new TSimpleServer(processor, serverTransport);

                Log.Information("Starting server on port {0}", port);
                server.Serve();
            }

            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }

            Log.Information("Done... closing");
        }
Exemple #6
0
        internal SimpleServer(int port)
        {
            TSampleService.Iface remoteService = new SampleService(port);

            TServerTransport transport = new TServerSocket(port);
            var processor = new TSampleService.Processor(remoteService);
            server = new TSimpleServer(processor, transport);
        }
Exemple #7
0
 public static void Start(int port)
 {
     TServerSocket serverTransport = new TServerSocket(port, 0, false);
     Login.Processor processor = new Login.Processor(new LoginHelper());
     TServer server = new TSimpleServer(processor, serverTransport);
     Console.WriteLine("Starting server on port {0} ...", port);
     server.Serve();
 }
 public void Start()
 {
     TServerSocket serverTransport = new TServerSocket(7911, 0, false);
     ThriftCase.Processor processor = new ThriftCase.Processor(new BusinessImpl());
     TServer server = new TSimpleServer(processor, serverTransport);
     Console.WriteLine("Starting server on port 7911 ...");
     server.Serve();
 }
		static void Main(string[] args)
		{
			TimeServiceImplementation service = new TimeServiceImplementation();
			TProcessor processor = new TimeService.Processor(service);
			TServerTransport transport = new TServerSocket(1337, 1000);
			TServer server = new TSimpleServer(processor, transport);

			server.Serve();
		}
        public static void EntryPoint()
        {
            ConfigController configController = ConfigController.Instance;
            ConfigService.Processor processor = new ConfigService.Processor(configController);
            TServerTransport serverTransport = new TServerSocket(9090);
            TServer server = new TSimpleServer(processor, serverTransport);

            server.Serve();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            TServerSocket serverTransport = new TServerSocket(7911);

             UserStorage.Processor processor = new UserStorage.Processor(new UserStorageImpl());
             // var protFactory = new TBinaryProtocol.Factory(true, true);
             var server = new TThreadPoolServer(processor, serverTransport);
             Console.WriteLine("Starting server on port 7911 ...");
             server.Serve();
        }
Exemple #12
0
 static void Main(string[] args)
 {
     int port = 8585;
     HelloHandler handler = new HelloHandler();
     helloSvc.Processor proc = new helloSvc.Processor(handler);
     TServerTransport trans = new TServerSocket(port, 0, true);
     TServer server = new TSimpleServer(proc, trans);
     Console.WriteLine("Server running on port " + port);
     server.Serve();
 }
Exemple #13
0
        static void Main(string[] args)
        {
            UserService.Processor processor = new UserService.Processor(new UserProxy());
            TServerSocket serverSocket = new TServerSocket(12000, 0, false);
            TServer server = new TSimpleServer(processor, serverSocket);

            Console.WriteLine("Starting the server...");
            server.Serve();

            Console.ReadLine();

        }
        public static void runSocketServer()
        {
            HelloWorldHandler handler = new HelloWorldHandler();
            HelloWorld.Processor processor = new HelloWorld.Processor(handler);
            TServerTransport serverTransport = new TServerSocket(9090);
            TServer server = new TSimpleServer(processor, serverTransport);

            // Use this for a multithreaded server
            // server = new TThreadPoolServer(processor, serverTransport);

            Console.WriteLine("Starting the server...");
            server.Serve();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            var handler = new ConverterHandler();
            var processor = new ConvertSvc.Processor(handler);
            var serverTransport = new TServerSocket(9090);
            var server = new TSimpleServer(processor, serverTransport);

            // Use this for a multithreaded server
            // server = new TThreadPoolServer(processor, serverTransport);

            Console.WriteLine("Starting the server...");
            server.Serve();
        }
        public void Run()
        {
            try
            {
                var processor = new MessageService.Processor(receiver);
                var serverTransport = new TServerSocket(port);
                server = new TThreadPoolServer(processor, serverTransport, new TTransportFactory(), new TCompactProtocol.Factory());

                Task.Factory.StartNew(() => server.Serve());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #17
0
        public static void Execute(string[] args)
        {
            try
            {
                bool useBufferedSockets = false;
                int port = 9090;
                if (args.Length > 0)
                {
                    port = int.Parse(args[0]);

                    if (args.Length > 1)
                    {
                        bool.TryParse(args[1], out useBufferedSockets);
                    }
                }

                // Processor
                TestHandler testHandler = new TestHandler();
                ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);

                // Transport
                TServerSocket tServerSocket = new TServerSocket(port, 0, useBufferedSockets);

                TServer serverEngine;

                // Simple Server
                serverEngine = new TSimpleServer(testProcessor, tServerSocket);

                // ThreadPool Server
                // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket);

                // Threaded Server
                // serverEngine = new TThreadedServer(testProcessor, tServerSocket);

                testHandler.server = serverEngine;

                // Run it
                Console.WriteLine("Starting the server on port " + port + (useBufferedSockets ? " with buffered socket" : "") + "...");
                serverEngine.Serve();

            }
            catch (Exception x)
            {
                Console.Error.Write(x);
            }
            Console.WriteLine("done.");
        }
        protected override void OnStart(string[] args)
        {
            int port;
            logger.Info(string.Format("{0} is starting.", this.ServiceName));

            if (!int.TryParse(ConfigurationManager.AppSettings[BIND_PORT_KEY], out port)) port = DEFAULT_PORT;
            TServerTransport trans = new TServerSocket(port);
            Inbound_ItemService.Processor proc = new Inbound_ItemService.Processor(new ItemServiceHandler());
            server = new TThreadPoolServer(proc, trans);

            serverTask = Task.Factory.StartNew(() =>
            {
                server.Serve();
            },TaskCreationOptions.LongRunning | TaskCreationOptions.AttachedToParent);

            logger.Info(string.Format("{0}:{1} started successfully.", this.ServiceName, port));
        }
 static void Main(string[] args)
 {
     try
     {
         MathServer handler = new MathServer();
         MathService.Processor processor = new MathService.Processor(handler);
         TServerTransport serverTransport = new TServerSocket(9095);
         TServer server = new TSimpleServer(processor, serverTransport);
         Console.WriteLine("Starting the server...");
         server.Serve();
     }
     catch (Exception x)
     {
         Console.WriteLine(x.StackTrace);
     }
     Console.WriteLine("done.");
 }
Exemple #20
0
    public static void StartSocket(int nPort, Action<string> debugAction)
    {
        try
        {
            CalculatorHandler handler = new CalculatorHandler();
            SendLog.Processor processor = new SendLog.Processor(handler);
            TServerTransport serverTransport = new TServerSocket(nPort);
            server = new TSimpleServer(processor, serverTransport);

           debugAction("开始监听端口:" + nPort);
            server.Serve();
        }
        catch (Exception x)
        {
            debugAction(x.StackTrace);
        }

        debugAction("停止监听, port:" + nPort);
    }
Exemple #21
0
        public static void Start()
        {
            try
            {
                RpcHanlder handler = new RpcHanlder();
                handler.init();
                Rpc.Processor processor = new Rpc.Processor(handler);
                TServerTransport serverTransport = new TServerSocket(9090);
                TServer server = new TSimpleServer(processor, serverTransport);

                // Use this for a multithreaded server
                // server = new TThreadPoolServer(processor, serverTransport);

                Console.WriteLine("Starting the server.....");
                server.Serve();
            }
            catch (Exception x)
            {
                Console.WriteLine(x.StackTrace);
            }
            Console.WriteLine("done.");
        }
Exemple #22
0
        static void Main(string[] args)
        {
            DNHPacketHandler handler = new DNHPacketHandler();
            DNHService.Processor processor = new DNHService.Processor(handler);

            TServerTransport serverTransport = new TServerSocket(9090);
            TServer server = new TThreadPoolServer(processor, serverTransport);

            Console.WriteLine("Starting the server...");
            server.Serve();
        }
        public static bool Execute(string[] args)
        {
            try
            {
                bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
                ServerType serverType = ServerType.TSimpleServer;
                ProcessorFactoryType processorFactoryType = ProcessorFactoryType.TSingletonProcessorFactory;
                int port = 9090;
                string pipe = null;
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-pipe")  // -pipe name
                    {
                        pipe = args[++i];
                    }
                    else if (args[i].Contains("--port="))
                    {
                        port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
                    }
                    else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
                    {
                        useBufferedSockets = true;
                    }
                    else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
                    {
                        useFramed = true;
                    }
                    else if (args[i] == "--compact" || args[i] == "--protocol=compact")
                    {
                        compact = true;
                    }
                    else if (args[i] == "--json" || args[i] == "--protocol=json")
                    {
                        json = true;
                    }
                    else if (args[i] == "--threaded" || args[i] == "--server-type=threaded")
                    {
                        serverType = ServerType.TThreadedServer;
                    }
                    else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool")
                    {
                        serverType = ServerType.TThreadPoolServer;
                    }
                    else if (args[i] == "--prototype" || args[i] == "--processor=prototype")
                    {
                        processorFactoryType = ProcessorFactoryType.TPrototypeProcessorFactory;
                    }
                    else if (args[i] == "--ssl")
                    {
                        useEncryption = true;
                    }
                }

                // Transport
                TServerTransport trans;
                if (pipe != null)
                {
                    trans = new TNamedPipeServerTransport(pipe);
                }
                else
                {
                    if (useEncryption)
                    {
                        string certPath = "../../../../test/keys/server.p12";
                        trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls);
                    }
                    else
                    {
                        trans = new TServerSocket(port, 0, useBufferedSockets);
                    }
                }

                TProtocolFactory proto;
                if (compact)
                    proto = new TCompactProtocol.Factory();
                else if (json)
                    proto = new TJSONProtocol.Factory();
                else
                    proto = new TBinaryProtocol.Factory();

                TProcessorFactory processorFactory;
                if (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory)
                {
                    processorFactory = new TPrototypeProcessorFactory<ThriftTest.Processor, TestHandler>();
                }
                else
                {
                    // Processor
                    TestHandler testHandler = new TestHandler();
                    ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);
                    processorFactory = new TSingletonProcessorFactory(testProcessor);
                }

                TTransportFactory transFactory;
                if (useFramed)
                    transFactory = new TFramedTransport.Factory();
                else
                    transFactory = new TTransportFactory();

                TServer serverEngine;
                switch (serverType)
                {
                    case ServerType.TThreadPoolServer:
                        serverEngine = new TThreadPoolServer(processorFactory, trans, transFactory, proto);
                        break;
                    case ServerType.TThreadedServer:
                        serverEngine = new TThreadedServer(processorFactory, trans, transFactory, proto);
                        break;
                    default:
                        serverEngine = new TSimpleServer(processorFactory, trans, transFactory, proto);
                        break;
                }

                //Server event handler
                TradeServerEventHandler serverEvents = new TradeServerEventHandler();
                serverEngine.setEventHandler(serverEvents);

                // Run it
                string where = (pipe != null ? "on pipe " + pipe : "on port " + port);
                Console.WriteLine("Starting the " + serverType.ToString() + " " + where +
                    (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory ? " with processor prototype factory " : "") +
                    (useBufferedSockets ? " with buffered socket" : "") +
                    (useFramed ? " with framed transport" : "") +
                    (useEncryption ? " with encryption" : "") +
                    (compact ? " with compact protocol" : "") +
                    (json ? " with json protocol" : "") +
                    "...");
                serverEngine.Serve();

            }
            catch (Exception x)
            {
                Console.Error.Write(x);
                return false;
            }
            Console.WriteLine("done.");
            return true;
        }
            public void Begin()
            {
                try
                {
                    var handler = new MultiplicationHandler();
                    var processor = new MultiplicationService.Processor(handler);
                    TServerTransport serverTransport = new TServerSocket(Port);
                    _server = new TSimpleServer(processor, serverTransport);
                    Console.WriteLine("Starting the server...");

                    // The next call will ...
                    // ... create a new thrift server on a new thread (Thrift design)
                    // ... that thread runs till server.Stop() is called
                    // ... this thread is blocked till then
                    _server.Serve();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                Console.WriteLine("Server, done.");
            }
Exemple #25
0
        public static void Execute(string[] args)
        {
            try
            {
                bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
                int port = 9090, i = 0;
                string pipe = null;
                if (args.Length > 0)
                {
                    i = 0;
                    if (args[i] == "-pipe")  // -pipe name
                    {
                        pipe = args[++i];
                    }
                    else  // default to port number (compatibility)
                    {
                        port = int.Parse(args[i]);
                    }

                    ++i;
                    if (args.Length > i)
                    {
                        if ( args[i] == "raw" )
                        {
                            // as default
                        }
                        else if (args[i] == "buffered")
                        {
                            useBufferedSockets = true;
                        }
                        else if (args[i] == "framed")
                        {
                            useFramed = true;
                        }
                        else if (args[i] == "ssl")
                        {
                            useEncryption = true;
                        }
                        else if (args[i] == "compact" )
                        {
                            compact = true;
                        }
                        else if (args[i] == "json" )
                        {
                            json = true;
                        }
                        else
                        {
                            // Fall back to the older boolean syntax
                            bool.TryParse(args[i], out useBufferedSockets);
                        }
                    }
                }

                // Processor
                TestHandler testHandler = new TestHandler();
                ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);

                // Transport
                TServerTransport trans;
                if( pipe != null)
                {
                    trans = new TNamedPipeServerTransport(pipe);
                }
                else
                {
                    if (useEncryption)
                    {
                        trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2("../../../../../keys/server.pem"));
                    }
                    else
                    {
                        trans = new TServerSocket(port, 0, useBufferedSockets);
                    }
                }

                TProtocolFactory proto;
                if ( compact )
                    proto = new TCompactProtocol.Factory();
                else if ( json )
                    proto = new TJSONProtocol.Factory();
                else
                    proto = new TBinaryProtocol.Factory();

                // Simple Server
                TServer serverEngine;
                if ( useFramed )
                    serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory(), proto);
                else
                    serverEngine = new TSimpleServer(testProcessor, trans, new TTransportFactory(), proto);

                // ThreadPool Server
                // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket);

                // Threaded Server
                // serverEngine = new TThreadedServer(testProcessor, tServerSocket);

                testHandler.server = serverEngine;

                // Run it
                string where = ( pipe != null ? "on pipe "+pipe : "on port " + port);
                Console.WriteLine("Starting the server " + where +
                    (useBufferedSockets ? " with buffered socket" : "") +
                    (useFramed ? " with framed transport" : "") +
                    (useEncryption ? " with encryption" : "") +
                    (compact ? " with compact protocol" : "") +
                    "...");
                serverEngine.Serve();

            }
            catch (Exception x)
            {
                Console.Error.Write(x);
            }
            Console.WriteLine("done.");
        }
        public static void Execute(string[] args)
        {
            try
            {
                bool useBufferedSockets = false, useFramed = false;
                int port = 9090;
                if (args.Length > 0)
                {
                    port = int.Parse(args[0]);

                    if (args.Length > 1)
                    {
                        if ( args[1] == "raw" )
                        {
                            // as default
                        }
                        else if ( args[1] == "buffered" )
                        {
                            useBufferedSockets = true;
                        }
                        else if ( args[1] == "framed" )
                        {
                            useFramed = true;
                        }
                        else
                        {
                            // Fall back to the older boolean syntax
                            bool.TryParse(args[1], out useBufferedSockets);
                        }
                    }
                }

                // Processor
                TestHandler testHandler = new TestHandler();
                ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);

                // Transport
                TServerSocket tServerSocket = new TServerSocket(port, 0, useBufferedSockets);

                // Simple Server
                TServer serverEngine;
                if ( useFramed )
                    serverEngine = new TSimpleServer(testProcessor, tServerSocket, new TFramedTransport.Factory());
                else
                    serverEngine = new TSimpleServer(testProcessor, tServerSocket);

                // ThreadPool Server
                // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket);

                // Threaded Server
                // serverEngine = new TThreadedServer(testProcessor, tServerSocket);

                testHandler.server = serverEngine;

                // Run it
                Console.WriteLine("Starting the server on port " + port +
                    (useBufferedSockets ? " with buffered socket" : "") +
                    (useFramed ? " with framed transport" : "") +
                    "...");
                serverEngine.Serve();

            }
            catch (Exception x)
            {
                Console.Error.Write(x);
            }
            Console.WriteLine("done.");
        }
Exemple #27
0
        public static void Execute(string[] args)
        {
            try
            {
                bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
                int port = 9090;
                string pipe = null;
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-pipe")  // -pipe name
                    {
                        pipe = args[++i];
                    }
                    else if (args[i].Contains("--port="))
                    {
                        port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1));
                    }
                    else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
                    {
                        useBufferedSockets = true;
                    }
                    else if (args[i] == "-f" || args[i] == "--framed"  || args[i] == "--transport=framed")
                    {
                        useFramed = true;
                    }
                    else if (args[i] == "--compact" || args[i] == "--protocol=compact")
                    {
                        compact = true;
                    }
                    else if (args[i] == "--json" || args[i] == "--protocol=json")
                    {
                        json = true;
                    }
                    else if (args[i] == "--ssl")
                    {
                        useEncryption = true;
                    }
                }

                // Processor
                TestHandler testHandler = new TestHandler();
                ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);

                // Transport
                TServerTransport trans;
                if( pipe != null)
                {
                    trans = new TNamedPipeServerTransport(pipe);
                }
                else
                {
                    if (useEncryption)
                    {
                        trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2("../../../../../keys/server.pem"));
                    }
                    else
                    {
                        trans = new TServerSocket(port, 0, useBufferedSockets);
                    }
                }

                TProtocolFactory proto;
                if ( compact )
                    proto = new TCompactProtocol.Factory();
                else if ( json )
                    proto = new TJSONProtocol.Factory();
                else
                    proto = new TBinaryProtocol.Factory();

                // Simple Server
                TServer serverEngine;
                if ( useFramed )
                    serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory(), proto);
                else
                    serverEngine = new TSimpleServer(testProcessor, trans, new TTransportFactory(), proto);

                // ThreadPool Server
                // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket);

                // Threaded Server
                // serverEngine = new TThreadedServer(testProcessor, tServerSocket);

            //Server event handler
            TradeServerEventHandler serverEvents = new TradeServerEventHandler();
            serverEngine.setEventHandler(serverEvents);

                testHandler.server = serverEngine;

                // Run it
                string where = ( pipe != null ? "on pipe "+pipe : "on port " + port);
                Console.WriteLine("Starting the server " + where +
                    (useBufferedSockets ? " with buffered socket" : "") +
                    (useFramed ? " with framed transport" : "") +
                    (useEncryption ? " with encryption" : "") +
                    (compact ? " with compact protocol" : "") +
                    (json ? " with json protocol" : "") +
                    "...");
                serverEngine.Serve();

            }
            catch (Exception x)
            {
                Console.Error.Write(x);
            }
            Console.WriteLine("done.");
        }