UDP面向无连接,给飞秋发送消息
[java] view plain copy- package com.wxh.day1017;
- //给飞秋发送消息
- import java.io.*;
- import java.net.*;
- public class Test {
- public static void main(String[] args) throws IOException {
- //飞秋的数据格式
- String str="1:100:Jack:dell:32:hello 你好啊";
- byte[] array=str.getBytes();
- //发送的管道
- DatagramSocket ds=new DatagramSocket();
- //数据包
- DatagramPacket dp=new DatagramPacket(array, array.length,InetAddress.getByName("125.220.70.16"),2425);
- //ds.send(dp);
- while(true){
- ds.send(dp);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }