Beispiel #1
0
        static void Main(string[] args)
        {
            INetRouterClient client = NetRouterClientFactory.CreateNetRouterClient("Test");

            //NETADDR addr = new NETADDR(8, 1, 0, 1, 3);
            //INetRouterClient client = NetRouterClientFactory.CreateNetRouterClient("Test", "172.168.0.1", 9003, "172.168.0.1", 9005, ref addr, "");

            List <NETADDR> netAddrList = new List <NETADDR>();

            netAddrList.Add(new NETADDR(8, 1, 0, 1, 3));
            StringBuilder sssb = new StringBuilder();

            for (int i = 0; i < 80; i++)
            {
                sssb.Append("AAABB");
            }
            byte[] byteArray = System.Text.Encoding.Default.GetBytes(sssb.ToString());

            client.start();


            #region 加上分包协议之后的发送
            TransMsgByPkgs transfer = new TransMsgByPkgs();

            //发送
            if (transfer.sendMsgByPackages(byteArray, netAddrList, client))
            {
                Console.WriteLine("发送成功!");
            }

            #endregion


            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            INetRouterClient client = NetRouterClientFactory.CreateNetRouterClient("Test");

            //NETADDR addr = new NETADDR(8, 1, 0, 1, 3);
            //INetRouterClient client = NetRouterClientFactory.CreateNetRouterClient("Test", "172.168.0.1", 9003, "172.168.0.1", 9005, ref addr, "");

            List <NETADDR> netAddrList = new List <NETADDR>();

            netAddrList.Add(new NETADDR(8, 1, 0, 1, 3));
            StringBuilder sssb = new StringBuilder();

            for (int i = 0; i < 80; i++)
            {
                sssb.Append("AAABB");
            }
            byte[] byteArray = System.Text.Encoding.Default.GetBytes(sssb.ToString());

            client.start();


            #region 加上分包协议之后的接收
            TransMsgByPkgs transfer = new TransMsgByPkgs();

            //接收
            REVMSGBYPACKAGES rsvMsg = new REVMSGBYPACKAGES();
            while (true)
            {
                while (transfer.receiveMsgByPackages(ref rsvMsg, client))
                {
                    string revmsgTemp = rsvMsg.msg;

                    Console.WriteLine(revmsgTemp.Length); //测试数据较大时,这里只显示组包后解析的字符串长度
                    Console.WriteLine(revmsgTemp);        //当测试信息数据比较短时,可以将信息显示出来
                }
            }
            #endregion


            Console.ReadLine();
        }
Beispiel #3
0
        public void ConnectToServer(string IP1, int Port1, string IP2, int Port2)
        {
            this.m_IP1   = IP1;
            this.m_Port1 = Port1;
            this.m_IP2   = IP2;
            this.m_Port2 = Port2;

            if (this.m_NetRouterClient == null)
            {
                this.m_NetRouterClient = NetRouterClientFactory.CreateNetRouterClient
                                             (this.m_ClientName, this.m_IP1, this.m_Port1, this.m_IP2, this.m_Port2, ref this.m_LocalAddr, "");
            }

            if (this.m_StatusStrAction != null)
            {
                this.m_StatusStrAction("正在连接路由服务器...");
            }
            while (!m_NetRouterClient.start())
            {
                Thread.Sleep(10);
            }
            if (this.m_StatusStrAction != null)
            {
                this.m_StatusStrAction("连接路由服务器成功!");
            }

            m_ThreadClose = false;

            m_ReceiveThread              = new Thread(this.ReceiveThreadMethod);
            m_ReceiveThread.Name         = "接收线程";
            m_ReceiveThread.IsBackground = true;
            m_ReceiveThread.Start();

            if (m_ConnectThread == null)
            {
                m_ConnectThread              = new Thread(this.ConnectionThreadMethod);
                m_ConnectThread.Name         = "保持连接线程";
                m_ConnectThread.IsBackground = true;
                m_ConnectThread.Start();
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            NETADDR localaddr = new NETADDR();

            localaddr.bureauCode = 8;
            localaddr.unitType   = 2;
            localaddr.unitId     = 0;
            localaddr.devType    = 1;
            localaddr.devId      = 6;


            INetRouterClient netRouterClient = NetRouterClientFactory.CreateNetRouterClient("Test", "172.168.0.1", 9003, "172.168.0.1", 9005, ref localaddr, "");

            while (!netRouterClient.start())
            {
                Console.Write("Start fails.\n");
                Thread.Sleep(10);
            }

            Console.Write("Start succeeds.\n");
            REVMSG recvMsg = new REVMSG();

            while (true)
            {
                while (netRouterClient.receiveMessage(ref recvMsg))
                {
                    string revmsgTemp = System.Text.Encoding.Default.GetString(recvMsg.msg, 0, 5);


                    Console.WriteLine(revmsgTemp);
                }
            }



            Console.ReadKey();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            NETADDR localaddr = new NETADDR();

            localaddr.bureauCode = 8;
            localaddr.unitType   = 2;
            localaddr.unitId     = 0;
            localaddr.devType    = 1;
            localaddr.devId      = 7;

            NETADDR remote1 = new NETADDR();

            remote1.bureauCode = 8;
            remote1.unitType   = 2;
            remote1.unitId     = 0;
            remote1.devType    = 1;
            remote1.devId      = 5;


            NETADDR remote2 = new NETADDR();

            remote2.bureauCode = 8;
            remote2.unitType   = 2;
            remote2.unitId     = 0;
            remote2.devType    = 1;
            remote2.devId      = 6;

            Console.WriteLine("Sender!!!!!!");
            INetRouterClient netRouterClient = NetRouterClientFactory.CreateNetRouterClient("Test", "172.168.0.1", 9003, "172.168.0.1", 9005, ref localaddr, "");

            while (!netRouterClient.start())
            {
                Console.Write("Start fails.\n");
                Thread.Sleep(10);
            }
            Console.Write("Start succeeds.\n");

            List <NETADDR> adrlist = new List <NETADDR>();

            adrlist.Add(remote1);
            adrlist.Add(remote2);
            string s = "Hello";

            byte[] data = new byte[65000];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = 1;
            }

            SENDMSG sMessage = new SENDMSG(ref data, ref adrlist);

            while (true)
            {
                if (!netRouterClient.sendMessage(ref sMessage))
                {
                    Console.Write("Send Wrong!\n");
                }
                Thread.Sleep(2000);
            }

            Console.ReadKey();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            NETADDR localaddr = new NETADDR();

            localaddr.bureauCode = 8;
            localaddr.unitType   = 2;
            localaddr.unitId     = 0;
            localaddr.devType    = 1;
            localaddr.devId      = 6;

            INetRouterClient netRouterClient = NetRouterClientFactory.CreateNetRouterClient("Test", "191.168.99.98", 9003, "10.2.48.123", 9005, ref localaddr, "");

            while (!netRouterClient.start())
            {
                Console.Write("Start fails.\n");
                Thread.Sleep(10);
            }
            Console.Write("Start succeeds.\n");
            while (true)
            {
                if (netRouterClient.isNet1Connected() || netRouterClient.isNet2Connected())
                {
                    if (SENDNUM + 1 < SENDNUM)
                    {
                        SENDNUM = 0;
                    }

                    REVMSG         recvMsg  = new REVMSG();
                    List <SENDMSG> sendlist = new List <SENDMSG>();
                    while (netRouterClient.receiveMessage(ref recvMsg))
                    {
                        string revmsgTemp = System.Text.Encoding.Default.GetString(recvMsg.msg, 0, recvMsg.msg.Length);

                        Console.WriteLine("Rev len : " + recvMsg.msg.Length);
                        Console.WriteLine("Rev (" + recvMsg.srcAddr.unitId + ":"
                                          + recvMsg.srcAddr.devId + ")---"
                                          + dataNum(revmsgTemp));

                        //Console.WriteLine("Rev (" + recvMsg.srcAddr.unitId + ":"
                        //                    + recvMsg.srcAddr.devId + ")---"
                        //                    + recvMsg.msg);

                        String ack = (++SENDNUM).ToString();
                        ack += " Hello!";
                        //byte[] tempByte = Encoding.Default.GetBytes(ack);

                        List <NETADDR> adrlist = new List <NETADDR>();
                        adrlist.Add(recvMsg.srcAddr);
                        SENDMSG sMessage = new SENDMSG(ref ack, ref adrlist);

                        sendlist.Add(sMessage);
                        if (!netRouterClient.sendMessage(ref sMessage))
                        {
                            Console.Write("Send Wrong!\n");
                        }
                        else
                        {
                            Console.WriteLine("Send -------- " + ack + " : " + ack.ToString().Length + "\n");
                        }
                    }
                }
                try {
                    Thread.Sleep(10);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    Console.Write(e.Message + "\n");
                }
            }
        }