Exemplo n.º 1
0
 static void Main(string[] args)
 {
     socketserver = new IoServer(60, 1024);
     ////////socketserver.Start("127.0.0.1", 6789);
     socketserver.Start(6789);
     socketserver.ReceiveEvent  = new onezl.iocp.ReceiveEventHandler(myfuncion);
     socketserver.DownLineEvent = new onezl.iocp.DownLineHandler(Downline);
     socketserver.Name          = "RegClean";
     Console.WriteLine("start");
 }
Exemplo n.º 2
0
        public void Start()
        {
            if (!RelayServer.GetInstance().CanStart())
            {
                return;
            }

            //表集合
            DataSet ds = FrmParam.ReadDataSet();

            //串口
            DataTable tableSerial = ds.Tables[FrmParam.s_GridSerial];
            DataTable tableServer = ds.Tables[FrmParam.s_GridServer];
            DataTable tableClient = ds.Tables[FrmParam.s_GridClient];
            DataTable tableRelay  = ds.Tables[FrmParam.s_GridRelay];

            if (tableSerial != null)
            {
                foreach (DataRow dr in tableSerial.Rows)
                {
                    SerialRow sr = new SerialRow(dr);
                    if (sr.select)
                    {
                        SerialPort sp     = new SerialPort("COM" + sr.port, sr.baud, (Parity)sr.parity);
                        IoSerial   serial = new IoSerial(sr.id, sp, this);

                        RelayServer.GetInstance().AddHeader(serial);
                    }
                }
            }

            if (tableServer != null)
            {
                foreach (DataRow dr in tableServer.Rows)
                {
                    ServerRow sr = new ServerRow(dr);
                    if (sr.select)
                    {
                        IoServer server = new IoServer(sr.id, sr.ip, sr.port, this);
                        RelayServer.GetInstance().AddHeader(server);
                    }
                }
            }

            if (tableClient != null)
            {
                foreach (DataRow dr in tableClient.Rows)
                {
                    ClientRow sr = new ClientRow(dr);
                    if (sr.select)
                    {
                        IoClient client = new IoClient(sr.id, sr.ip, sr.port, this);
                        RelayServer.GetInstance().AddHeader(client);
                    }
                }
            }

            if (tableRelay != null)
            {
                foreach (DataRow dr in tableRelay.Rows)
                {
                    RelayRow sr = new RelayRow(dr);
                    if (sr.select)
                    {
                        RelayServer.GetInstance().AddRelay(sr.id1, sr.id2);
                    }
                }
            }

            RelayServer.GetInstance().Start();
        }