Esempio n. 1
0
        private static void HandleSession(TcpClient tcpclient)
        {
            using (StreamReader reader = new StreamReader(tcpclient.GetStream()))
            {
                string header = reader.ReadLine();
                Dictionary <string, string> args = serializer.Deserialize <Dictionary <string, string> >(header);

                Console.Out.WriteLine("Request Header : {0}", header);

                string source = null;
                if (args.ContainsKey("source"))
                {
                    source = args["source"];
                }
                if (source != null && source.Equals("opc"))
                {
                    new OPCProxy(tcpclient, reader, args).HandleRequest();
                }
                else
                {
                    PHDProxy.HandleRequest(tcpclient, reader, args);
                }

                Console.Out.WriteLine("###END###");
            }


            if (tcpclient.Connected)
            {
                tcpclient.Close();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (HasOption(args, "c"))
            {
                if (HasOption(args, "opc"))
                {
                    OPCProxy.SendRequest(args);
                }
                else
                {
                    PHDProxy.SendRequest(args);
                }

                return;
            }
            else if (HasOption(args, "s"))
            {
                Task server = new Task(() =>
                {
                    listen = new TcpListener(System.Net.IPAddress.Parse("127.0.0.1"), SERVER_PORT);

                    listen.Start();
                    Console.Out.WriteLine("Server: start server .............................. \n");

                    while (true)
                    {
                        TcpClient client = listen.AcceptTcpClient();
                        Console.Out.WriteLine("Accept a new request !\n");

                        Task clientTask = new Task(() =>
                        {
                            HandleSession(client);
                        });

                        clientTask.Start();
                    }
                });

                server.Start();
                server.Wait();
            }
            else
            {
                Usage();
            }
        }