java实现UDP请求

来源:互联网 发布:逆战原子0.19秒宏数据 编辑:程序博客网 时间:2024/06/08 09:39

1.   http://blog.csdn.net/canot/article/details/50587372

2.   Udp协议:

3. importjava.net.DatagramPacket;

4. importjava.net.DatagramSocket;

5. importjava.net.InetAddress;

6.  

7. public class feiq {

8.  

9. public static voidmain(String[] args) throws Exception {

10.        

11.            for(inti=1;i<=5;i++){

12.            String content="1_lbt4_10#32899#002481627512#0#0#0:"

13.                 + "1289671407:Administrator:MICROSO-697TGLD:288:"

14.                 + "一日不见,好想你 ";

15.            byte[] sentBuf=content.getBytes("GBK");

16.        

17.            DatagramSocket  client = newDatagramSocket();

18.            InetAddress addr =InetAddress.getByName("172.18.21.133");

19.            int port =2425;

20.            DatagramPacket sendPacket

21.              = newDatagramPacket(sentBuf,sentBuf.length,addr,port);

22.            client.send(sendPacket);

23.            client.close();

24.            }

25.       

26.         }

27.       

28. }

0 0
原创粉丝点击