コード例 #1
0
        public static void InitializeProcessor()
        {
            XmlDocument cfg = new XmlDocument();
            cfg.Load("remoteconfig.xml");

            //*********************Loading External Devices************
            XmlNodeList nlist = cfg.SelectNodes("ProcessorConfiguration/ExternalDevice");
            IExternalDevicePort[] externaldevices = null;
            if(nlist.Count>0)
            {
                Console.WriteLine("Loading External Devices");
                externaldevices = new ExternalDevicePort[nlist.Count];
                int tmp2=0;
                foreach(XmlNode tmp in nlist)
                {
                    externaldevices[tmp2] = new ExternalDevicePort(
                        tmp.SelectSingleNode("Name").InnerText
                        ,new ExternalDevicePort.Echo(EchoMessage));
                    externaldevices[tmp2].Initialize(int.Parse(
                        tmp.SelectSingleNode("Port").InnerText));
                    tmp2++;
                }
            }

            server = new RemoteRequestServer(int.Parse(cfg.SelectSingleNode(
                "ProcessorConfiguration/Port").InnerText),
                cfg.SelectSingleNode("ProcessorConfiguration/Name").InnerText,externaldevices);

            threadstacksize =int.Parse(cfg.SelectSingleNode(
                "ProcessorConfiguration/ThreadStackSize").InnerText);
        }
コード例 #2
0
        public static void InitializeProcessor()
        {
            XmlDocument cfg = new XmlDocument();

            cfg.Load("remoteconfig.xml");

            //*********************Loading External Devices************
            XmlNodeList nlist = cfg.SelectNodes("ProcessorConfiguration/ExternalDevice");

            IExternalDevicePort[] externaldevices = null;
            if (nlist.Count > 0)
            {
                Console.WriteLine("Loading External Devices");
                externaldevices = new ExternalDevicePort[nlist.Count];
                int tmp2 = 0;
                foreach (XmlNode tmp in nlist)
                {
                    externaldevices[tmp2] = new ExternalDevicePort(
                        tmp.SelectSingleNode("Name").InnerText
                        , new ExternalDevicePort.Echo(EchoMessage));
                    externaldevices[tmp2].Initialize(int.Parse(
                                                         tmp.SelectSingleNode("Port").InnerText));
                    tmp2++;
                }
            }


            server = new RemoteRequestServer(int.Parse(cfg.SelectSingleNode(
                                                           "ProcessorConfiguration/Port").InnerText),
                                             cfg.SelectSingleNode("ProcessorConfiguration/Name").InnerText, externaldevices);

            threadstacksize = int.Parse(cfg.SelectSingleNode(
                                            "ProcessorConfiguration/ThreadStackSize").InnerText);
        }
コード例 #3
0
        public static void ThreadProc()
        {
            while(serverstate != ServerThreadStates.EXIT )
            {
                switch(serverstate){

                    case ServerThreadStates.CONNECTED:
                        Console.WriteLine("Recieving data packet....");
                        try
                        {
                            server.RecievePacket();
                        }
                        catch (Exception e){
                            Console.WriteLine(e.Message);
                            if(!manualstop)
                            {
                                Console.WriteLine("Restarting Server....");
                                serverstate = ServerThreadStates.RESTART;
                            }
                            else
                                manualstop=false;
                        }
                        break;

                    case ServerThreadStates.START:
                        InitializeProcessor();
                        Console.WriteLine("Processor Name : " + server.processorname);
                        Console.WriteLine("Listening on port : " + server.localprt.ToString());
                        if(server.Start())
                        {
                            serverstate = ServerThreadStates.CONNECTED;
                            Console.WriteLine("Connected to : " + ((IPEndPoint) server.listenersocket.RemoteEndPoint).Address.ToString());
                        }
                        else
                            if(!manualstop)
                            {
                                Console.WriteLine("Restarting Server....");
                                serverstate = ServerThreadStates.RESTART;
                            }else
                                manualstop=false;
                        break;

                    case ServerThreadStates.STOP:
                        if(!Object.ReferenceEquals(server,null))
                        {
                            server.Stop();
                            server=null;
                            Console.WriteLine("Server has been stopped.");
                        }
                        Thread.CurrentThread.Suspend();
                        break;

                    case ServerThreadStates.RESTART:
                        if(!Object.ReferenceEquals(server,null)){
                            server.Stop();
                            server=null;
                        }
                        serverstate = ServerThreadStates.START;
                        break;
                }
            }
            server = null;
        }
コード例 #4
0
        public static void ThreadProc()
        {
            while (serverstate != ServerThreadStates.EXIT)
            {
                switch (serverstate)
                {
                case ServerThreadStates.CONNECTED:
                    Console.WriteLine("Recieving data packet....");
                    try
                    {
                        server.RecievePacket();
                    }
                    catch (Exception e) {
                        Console.WriteLine(e.Message);
                        if (!manualstop)
                        {
                            Console.WriteLine("Restarting Server....");
                            serverstate = ServerThreadStates.RESTART;
                        }
                        else
                        {
                            manualstop = false;
                        }
                    }
                    break;

                case ServerThreadStates.START:
                    InitializeProcessor();
                    Console.WriteLine("Processor Name : " + server.processorname);
                    Console.WriteLine("Listening on port : " + server.localprt.ToString());
                    if (server.Start())
                    {
                        serverstate = ServerThreadStates.CONNECTED;
                        Console.WriteLine("Connected to : " + ((IPEndPoint)server.listenersocket.RemoteEndPoint).Address.ToString());
                    }
                    else
                    if (!manualstop)
                    {
                        Console.WriteLine("Restarting Server....");
                        serverstate = ServerThreadStates.RESTART;
                    }
                    else
                    {
                        manualstop = false;
                    }
                    break;

                case ServerThreadStates.STOP:
                    if (!Object.ReferenceEquals(server, null))
                    {
                        server.Stop();
                        server = null;
                        Console.WriteLine("Server has been stopped.");
                    }
                    Thread.CurrentThread.Suspend();
                    break;

                case ServerThreadStates.RESTART:
                    if (!Object.ReferenceEquals(server, null))
                    {
                        server.Stop();
                        server = null;
                    }
                    serverstate = ServerThreadStates.START;
                    break;
                }
            }
            server = null;
        }