首页 新闻 搜索 专区 学院

一个udp的代码如下怎么精简点减少代码量

0
悬赏园豆:10 [已解决问题] 解决于 2018-10-15 14:44

byte[] ff = { 0x55, 0xAA, 0x90, 0x00, 0x00, 0x00, 0x90};
IPEndPoint MyRemoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
MyClient2.Send(ff, ff.Length, MyRemoteEndPoint);

        byte[] ff1 = { 0x55, 0xAA, 0x91, 0x00, 0x00, 0x00, 0x91 };
        IPEndPoint MyRemoteEndPoint1 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff1, ff1.Length, MyRemoteEndPoint1);

        byte[] ff2= { 0x55, 0xAA, 0x92, 0x00, 0x00, 0x00, 0x92 };
        IPEndPoint MyRemoteEndPoint2 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff2, ff2.Length, MyRemoteEndPoint2);

        byte[] ff3 = { 0x55, 0xAA, 0x93, 0x00, 0x00, 0x00, 0x93 };
        IPEndPoint MyRemoteEndPoint3 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff3, ff3.Length, MyRemoteEndPoint3);

        byte[] ff4 = { 0x55, 0xAA, 0x94, 0x00, 0x00, 0x00, 0x94 };
        IPEndPoint MyRemoteEndPoint4 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff4, ff4.Length, MyRemoteEndPoint4);

        byte[] ff5 = { 0x55, 0xAA, 0x95, 0x00, 0x00, 0x00, 0x95 };
        IPEndPoint MyRemoteEndPoint5 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff5, ff5.Length, MyRemoteEndPoint5);

        byte[] ff6 = { 0x55, 0xAA, 0x96, 0x00, 0x00, 0x00, 0x96 };
        IPEndPoint MyRemoteEndPoint6 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff6, ff6.Length, MyRemoteEndPoint6);

        byte[] ff7 = { 0x55, 0xAA, 0x97, 0x00, 0x00, 0x00, 0x97 };
        IPEndPoint MyRemoteEndPoint7 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff7, ff7.Length, MyRemoteEndPoint7);

        byte[] ff8 = { 0x55, 0xAA, 0x98, 0x00, 0x00, 0x00, 0x98 };
        IPEndPoint MyRemoteEndPoint8 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff8, ff8.Length, MyRemoteEndPoint8);

        byte[] ff9 = { 0x55, 0xAA, 0x99, 0x00, 0x00, 0x00, 0x99 };
        IPEndPoint MyRemoteEndPoint9 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff9, ff9.Length, MyRemoteEndPoint9);


        byte[] ff10 = { 0x55, 0xAA, 0x9A, 0x00, 0x00, 0x00, 0x9A };
        IPEndPoint MyRemoteEndPoint10 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff10, ff10.Length, MyRemoteEndPoint10);

        byte[] ff11 = { 0x55, 0xAA, 0x9B, 0x00, 0x00, 0x00, 0x9B };
        IPEndPoint MyRemoteEndPoint11 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff11, ff11.Length, MyRemoteEndPoint11);

        byte[] ff12 = { 0x55, 0xAA, 0x9C, 0x00, 0x00, 0x00, 0x9C };
        IPEndPoint MyRemoteEndPoint12 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff12, ff12.Length, MyRemoteEndPoint12);

        byte[] ff13 = { 0x55, 0xAA, 0x9D, 0x00, 0x00, 0x00, 0x9D };
        IPEndPoint MyRemoteEndPoint13 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff13, ff13.Length, MyRemoteEndPoint13);

        byte[] ff14 = { 0x55, 0xAA, 0x9E, 0x00, 0x00, 0x00, 0x9E };
        IPEndPoint MyRemoteEndPoint14 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff14, ff14.Length, MyRemoteEndPoint14);

        byte[] ff15 = { 0x55, 0xAA, 0x9F, 0x00, 0x00, 0x00, 0x9F };
        IPEndPoint MyRemoteEndPoint15 = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);
        MyClient2.Send(ff15, ff15.Length, MyRemoteEndPoint15);
菜鸡你n+1号的主页 菜鸡你n+1号 | 初学一级 | 园豆:15
提问于:2018-10-15 14:18
< >
分享
最佳答案
0

udp是异步的,所以,Client可以重用的吧。实例化一个就可以了。然后:

IPEndPoint MyRemoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.15.255"), 8234);

MyClient2.Send({ 0x55, 0xAA, 0x9F, 0x00, 0x00, 0x00, 0x9C}, 7, MyRemoteEndPoint15);
MyClient2.Send({ 0x55, 0xAA, 0x9F, 0x00, 0x00, 0x00, 0x9D }, 7, MyRemoteEndPoint15);
MyClient2.Send({ 0x55, 0xAA, 0x9F, 0x00, 0x00, 0x00, 0x9E }, 7, MyRemoteEndPoint15);
MyClient2.Send({ 0x55, 0xAA, 0x9F, 0x00, 0x00, 0x00, 0x9F }, 7, MyRemoteEndPoint15);

收获园豆:10
ensleep | 小虾三级 |园豆:1403 | 2018-10-15 14:32

OK,谢谢

菜鸡你n+1号 | 园豆:15 (初学一级) | 2018-10-15 14:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册