Ejemplo n.º 1
0
        public void Start()
        {
            TServerSocket serverTransport = new TServerSocket(7911, 0, true);

            Thrift.Protocol.TMultiplexedProcessor processor = new Thrift.Protocol.TMultiplexedProcessor();

            processor.RegisterProcessor("SecondService", new SecondService.Processor(new SecondServiceImpl()));

            processor.RegisterProcessor("ThriftTest", new ThriftTest.Processor(new ThriftTestImpl()));

            //Impl.ThriftTestImpl handler = new ThriftTestImpl();
            //ThriftTest.Processor processor = new ThriftTest.Processor(handler);

            // TServer server = new TSimpleServer(processor, serverTransport);
            TServer server = new TThreadPoolServer(
                processor,
                serverTransport,
                new TFramedTransport.Factory(),
                new TBinaryProtocol.Factory());

            // TServer server = new TThreadPoolServer(processor, serverTransport);

            Console.WriteLine("Starting server on port 7911 ...");
            server.Serve();
        }
Ejemplo n.º 2
0
        public TransportWindow(ClientController clientController, int port)
        {
            InitializeComponent();
            StartPosition         = FormStartPosition.CenterScreen;
            ridesView.ReadOnly    = true;
            bookingsView.ReadOnly = true;
            bookingsView.Columns.Cast <DataGridViewColumn>().ToList().ForEach(f => f.SortMode = DataGridViewColumnSortMode.NotSortable);
            _clientController              = clientController;
            _clientController.UpdateEvent += _clientController_UpdateEvent;

            NotifyOnEvent();
            var clientProcessor = new ITransportObserver.Processor(_clientController);

            var processor = new TMultiplexedProcessor();

            processor.RegisterProcessor(nameof(ITransportServer.Iface), clientProcessor);

            var trasport = new TServerSocket(port);

            _server     = new TThreadPoolServer(processor, trasport);
            FormClosed += (a, b) => {
                _clientController.Logout();
                _clientController.UpdateEvent -= _clientController_UpdateEvent;
                _server.Stop();
            };
            _updates = Task.Run(() =>
            {
                _server.Serve();
            });
        }
        private static void Main(string[] args)
        {
            var bookServiceHandler        = new BookServiceHandler();
            var userAccountServiceHandler = new UserAccountServiceHandler();

            var bookServiceProcessor = new BookService.Processor(bookServiceHandler);
            var userAccountProcessor = new UserAccountService.Processor(userAccountServiceHandler);

            var processor = new TMultiplexedProcessor();

            processor.RegisterProcessor(nameof(BookService), bookServiceProcessor);
            processor.RegisterProcessor(nameof(UserAccountService), userAccountProcessor);

            TServerTransport transport = new TServerSocket(9090);
            TServer          server    = new TThreadPoolServer(processor, transport); // TThreadPoolServer accepts multiple clients

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

            // Start server on a different background thread so the console continues to be responsive
            var serverThread = new Thread(() => server.Serve())
            {
                IsBackground = true
            };

            serverThread.Start();

            Console.WriteLine("Done. Press any key to stop the server...");
            Console.ReadKey(true);

            server.Stop();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 要注册的服务器列表,注意一个服务只能注册一次,否则会失败(port不能重复注册)
 /// </summary>
 /// <param name="servers"></param>
 public void Register(SuperGMSServer[] servers)
 {
     try
     {
         if (servers == null || servers.Length < 1)
         {
             throw new Exception("no Server can Register");
         }
         foreach (SuperGMSServer s in servers)
         {
             TServerSocket           serverTransport = new TServerSocket(s.Config.Port);
             TBinaryProtocol.Factory factory         = new TBinaryProtocol.Factory();//传输协议
             TProcessor processor = new ThriftService.Processor(s.Server);
             TServer    server    = new TThreadPoolServer(processor, serverTransport, new TTransportFactory(), factory);
         }
     }
     catch (TTransportException tex)
     {
         //等log组件改造完之后再记录
     }
     catch (Exception ex)
     {
         //等log组件改造完之后再记录
     }
 }
        /// <summary>
        /// The start server.
        /// </summary>
        /// <param name="inputFile">
        /// The input file (vocabulary).
        /// </param>
        /// <param name="port">
        /// The server port.
        /// </param>
        public void Run(string inputFile, int port)
        {
            this.reader.AddVocabulary(File.OpenText(inputFile));

            try
            {
                var              service   = new AutoCompleteServiceImplementation();
                TProcessor       processor = new AutoCompleteService.Processor(service);
                TServerTransport transport = new TServerSocket(port);

                this.server = new TThreadPoolServer(
                    processor,
                    transport,
                    new TTransportFactory(),
                    new TTransportFactory(),
                    new TBinaryProtocol.Factory(),
                    new TBinaryProtocol.Factory(),
                    1,
                    this.Throughput,
                    (t) => { });

                Logger.Info("The THRIFT server is ready. Listening {0} port ...", port);
                this.server.Serve();
            }
            catch (Exception ce)
            {
                Logger.Error("An exception occurred: {0}", ce.Message);
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            try
            {
                //设置服务端口为8080
                TServerSocket serverTransport = new TServerSocket(9081);

                //设置传输协议工厂
                TBinaryProtocol.Factory factory = new TBinaryProtocol.Factory();

                //关联处理器与服务的实现
                TProcessor helloProcessor  = new HelloService.Processor(new MyHelloService());
                TProcessor schoolProcessor = new SchoolService.Processor(new MySchoolService());

                //创建服务端对象
                var processorMulti = new TMultiplexedProcessor();
                processorMulti.RegisterProcessor("helloService", helloProcessor);
                processorMulti.RegisterProcessor("schoolService", schoolProcessor);
                TServer server = new TThreadPoolServer(processorMulti, serverTransport, new TTransportFactory(), factory);

                Console.WriteLine("服务端正在监听9081端口");

                server.Serve();
            }
            catch (TTransportException ex)//捕获异常信息
            {
                //打印异常信息
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            try
            {
                int ServerPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ThriftServerPort"]);
                //设置服务端口
                TServerSocket serverTransport = new TServerSocket(ServerPort);

                //设置传输协议工厂
                TBinaryProtocol.Factory factory = new TBinaryProtocol.Factory();

                //关联处理器与服务的实现
                TProcessor processor = new QuesService.Processor(new Question());

                //创建服务端对象
                TServer server = new TThreadPoolServer(processor, serverTransport, new TTransportFactory(), factory);

                Console.WriteLine("试题服务端正在监听" + ServerPort + "端口");
                server.Serve();

                Console.ReadLine();
            }
            catch (TTransportException ex)
            {
                //打印异常信息
                Console.WriteLine(ex.Message);
            }
        }
 private void Dispose(bool disposing)
 {
     if (disposing && server != null)
     {
         server.Stop();
         server = null;
     }
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            TServerTransport transport = new TServerSocket(8800);                          //监听8800端口
            var     processor          = new UserService.Processor(new UserServiceImpl()); //设置实现类
            TServer server             = new TThreadPoolServer(processor, transport);

            server.Serve();
        }
Ejemplo n.º 10
0
        public static void Run(Iface processor, int port)
        {
            var pc =
                new Processor(processor);
            var serverTransport = new TServerSocket(port);
            var server          = new TThreadPoolServer(pc, serverTransport);

            server.Serve();
        }
Ejemplo n.º 11
0
        private static void ThreadStartPoint()
        {
            GrafoCB hwServer = new GrafoCB(true);

            GrafoService.Processor processor       = new GrafoService.Processor(hwServer);
            TServerTransport       serverTransport = new TServerSocket(Convert.ToInt16(VariaveisGlobais.servidorLocal.Porta));
            TServer server = new TThreadPoolServer(processor, serverTransport);

            server.Serve();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Starts the adapter server
        /// </summary>
        public void Start()
        {
            //Create a new server transport
            TServerTransport serverTransport = new TServerSocket(this.port);

            //Use a multithreaded server
            this.server = new TThreadPoolServer(this.processor, serverTransport, new BufferedTransportFactory(), new TCompactProtocol.Factory());

            this.server.Serve();
        }
Ejemplo n.º 13
0
        public void Start(int port = 10001)
        {
            SpeakService.Processor processor = new SpeakService.Processor(Instance);
            TServerTransport       transport = new TServerSocket(port);
            TServer server = new TThreadPoolServer(processor, transport);

            Console.WriteLine("server 10001 starting...");
            server.Serve();
            transport.Close();
        }
Ejemplo n.º 14
0
        public SocketServer(int port) : base(port)
        {
            CallFuncThriftEx <T> handler = new CallFuncThriftEx <T>();

            CallFuncThrift.Processor processor       = new CallFuncThrift.Processor(handler);
            TServerTransport         serverTransport = new TServerSocket(port);

            server = new TThreadPoolServer(processor, serverTransport);
            Logger.log("创建ThriftServer", $"端口号:{port}");
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            var handler   = new LibraryServiceHandler();
            var processor = new LibraryService.Processor(handler);

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

            server.Serve();
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            TServerSocket serverTransport = new TServerSocket(CommonHelper.ThriftPort, 0, false);

            Helloword.Processor processor = new Helloword.Processor(new HellowordThrift());
            TServer             server    = new TThreadPoolServer(processor, serverTransport);

            Console.WriteLine($"RpcServer started on {CommonHelper.ThriftPort}");
            server.Serve();
            Console.ReadKey();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Starts the adapter server
        /// </summary>
        public void Start()
        {
            MMIAdapter.Processor processor = new MMIAdapter.Processor(implementation);

            TServerTransport serverTransport = new TServerSocket(this.port);

            //Use a multithreaded server
            this.server = new TThreadPoolServer(processor, serverTransport, new BufferedTransportFactory(), new TCompactProtocol.Factory());

            this.server.Serve();
        }
        static async void StartServers(Handler handler)
        {
            await Task.Run(() => {
                var processor = new TheGraph.Thrift.TheGraph.Processor(handler);
                TServerTransport serverTransport = new TServerSocket(handler.port);
                TServer server = new TThreadPoolServer(processor, serverTransport);

                Console.WriteLine("Thrift Iniciou");
                server.Serve();
            });
        }
        static void RunNotificationService()
        {
            var handler   = new NotificationHandler();
            var processor = new NotificationService.Processor(handler);

            TServerTransport transport = new TServerSocket(9091);
            TServer          server    = new TThreadPoolServer(processor, transport);

            Console.WriteLine("start serving...");
            server.Serve();
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            var handler   = new ThriftServiceHandler();
            var processor = new MultiplicationService.Processor(handler);

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

            Console.WriteLine("going to serve...");

            server.Serve();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            /*IService server = new ServerObjectProxy("127.0.0.1", 55555);
             *
             * LoginForm loginForm = new LoginForm();
             * loginForm.setService(server);
             * loginForm.Text = "Login";
             *
             * TripsForm tripsForm = new TripsForm();
             * loginForm.setTripsForm(tripsForm);
             *
             * tripsForm.Text = "Trips";
             * tripsForm.setService(server);
             * tripsForm.SetLogin(loginForm);
             *
             * Application.Run(loginForm);*/


            var socket   = new TSocket("localhost", 55556);
            var protocol = new TBinaryProtocol(socket);
            var client   = new ThriftService.Client(protocol);

            socket.Open();

            ClientController controller = new ClientController(client);

            LoginForm loginForm = new LoginForm(controller);
            TripsForm tripsForm = new TripsForm(controller);

            var tripsControllerImpl = new TripsControllerImpl(tripsForm);
            var processor           = new TripsController.Processor(tripsControllerImpl);

            int port = 55555 + new Random().Next() % 10;
            TServerTransport transport = new TServerSocket(port);
            TServer          server    = new TThreadPoolServer(processor, transport);

            loginForm.setTripsForm(tripsForm, port);
            loginForm.Text = "Client on port " + port;
            tripsForm.SetLogin(loginForm);
            tripsForm.Text = "Client on port " + port;

            Thread thread = new Thread(new ThreadStart(server.Serve));

            thread.Start();

            Application.Run(loginForm);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 开始抓拍
        /// </summary>
        /// <param name="ob"></param>
        public void StartServer(object ob)
        {
            try
            {
                //在新线程中创建监听,接收服务器实时抓拍数据
                Thread ThListenServerRealtimeCapInfo = new Thread(new ParameterizedThreadStart(ListenWaitServerRealtimeCapInfo));
                ThListenServerRealtimeCapInfo.SetApartmentState(ApartmentState.STA);
                ThListenServerRealtimeCapInfo.IsBackground = true;
                ThListenServerRealtimeCapInfo.Start();

                //在新线程中创建监听,接收服务器实时比对数据
                Thread ThListenServerRealtimeCmpInfo = new Thread(new ParameterizedThreadStart(ListenWaitServerRealtimeCmpInfo));
                ThListenServerRealtimeCmpInfo.SetApartmentState(ApartmentState.STA);
                ThListenServerRealtimeCmpInfo.IsBackground = true;
                ThListenServerRealtimeCmpInfo.Start();

                try//捕获异常
                {
                    // 1.创建一个XmlDocument类的对象
                    XmlDocument xmlDoc = new XmlDocument();
                    // 2.读取的xml文档加载进来
                    string strXmlPath = System.Environment.CurrentDirectory + @"\ConfigFolder\port.xml";
                    xmlDoc.Load(strXmlPath);

                    // 3.读取你指定的节点
                    XmlNodeList lis = xmlDoc.GetElementsByTagName("StartupPort");
                    //获得节点下的所有子节点
                    XmlNodeList xndList = lis[0].ChildNodes;

                    //获得第一个子节点,得到抓拍ID
                    XmlNode xnd0 = xndList[0];
                    int     port = 0;
                    port = int.Parse(xnd0.InnerText);
                    TServerSocket      serverTransport = new TServerSocket(port, 0, false);
                    UIServer.Processor processor       = new UIServer.Processor(_UIServerInter);
                    server = new TThreadPoolServer(processor, serverTransport);
                    server.Serve();
                }
                catch (Exception ex)
                {
                    MyMessage.showYes(ex.Message);
                    return;
                }
            }
            catch (Exception ex)
            {
                _WriteLog.WriteToLog("StartServer", ex);
                return;
            }
        }
Ejemplo n.º 23
0
        public void Start()
        {
            if (_server != null)
            {
                throw new InvalidOperationException("Cannot start server that has already been started");
            }
            WPWithinCallback.Processor processor       = new WPWithinCallback.Processor(this);
            TServerTransport           serverTransport = _config.GetThriftServerTransport();
            TServer server = new TThreadPoolServer(processor, serverTransport);

            Log.InfoFormat("Starting callback server on {0}", _config.ServiceHost);
            _serverTask = Task.Run(() => server.Serve());
            _server     = server;
        }
Ejemplo n.º 24
0
        public static void Run(int port)
        {
            HelloWorldServer client = new HelloWorldServer();

            HelloWorldService.Processor processor = new global::HelloWorldService.Processor(client);
            TServerTransport            transport = new TServerSocket(port);
            TServer server = new TThreadPoolServer(processor, transport);

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

            server.Serve();

            transport.Close();
        }
Ejemplo n.º 25
0
        public static void Run()
        {
            TServerTransport serverTransport = new TServerSocket(8005);

            TTransportFactory transportFactory = new TTransportFactory();

            TProtocolFactory protocolFactory = new TCompactProtocol.Factory();

            var processor = new IUserService.Processor(new UserService());

            var server = new TThreadPoolServer(processor, serverTransport, transportFactory, protocolFactory);

            server.Serve();
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            TBinaryProtocol.Factory factory         = new TBinaryProtocol.Factory();
            TServerSocket           serverTransport = new TServerSocket(7912, 0, false);

            IAgent.Processor processor = new IAgent.Processor(new AgentImpl());
            //TServer server1 = new TSimpleServer(processor, serverTransport);
            TServer server = new TThreadPoolServer(processor, serverTransport, new TTransportFactory(), factory);



            Console.WriteLine("Starting server on port 7912 ...");
            server.Serve();
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            MySampleService service = new MySampleService();

            SampleService.Processor processor = new SampleService.Processor(service);

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

            System.Console.WriteLine("server listening at tcp://localhost:10240/");
            //绑定
            server.setEventHandler(new ServerTServerEventHandler());

            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);
            }
        }
Ejemplo n.º 29
0
        public static void StartServer()
        {
            SearchServiceHandler handler = new SearchServiceHandler();

            SearchService.Processor processor = new SearchService.Processor(handler);

            TMultiplexedProcessor multiProcessor = new TMultiplexedProcessor();

            multiProcessor.RegisterProcessor("search_service", processor);

            TServerTransport serverTransport = new TServerSocket(9090);
            var     a      = new TFramedTransport.Factory();
            TServer server = new TThreadPoolServer(multiProcessor, serverTransport, new TFramedTransport.Factory(), new TBinaryProtocol.Factory());

            serverTask = Task.Factory.StartNew(server.Serve);
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            TServerSocket serverTransport = new TServerSocket(7911, 0, false);

            Helloword.Processor processor = new Helloword.Processor(new HellowordThrift());
            //TServer server = new TSimpleServer(processor, serverTransport);
            //TServer server = new TThreadedServer(processor, serverTransport);
            TServer server = new TThreadPoolServer(processor, serverTransport);

            Console.WriteLine("Starting server on port 7911 ...");
            server.Serve();



            Console.ReadKey();
        }