📄 udp.java
字号:
import java.net.*;
import java.util.*;
public class Udp{
DatagramSocket ds;
DatagramPacket dp;
InetAddress addr;
public static final int PORT = 1111;
public static void main(String[] args)throws Exception{
Udp udp = new Udp(args[0]);
udp.go();
}
public Udp(String target)throws Exception{
addr = InetAddress.getByName(target);
ds = new DatagramSocket();
}
public void go()throws Exception{
byte[] buff;
for(;;){
Thread.sleep(2000);
System.out.println("sending");
String s = (new Date()).toString();
buff = s.getBytes();
dp = new DatagramPacket(buff,buff.length,addr,PORT);
ds.send(dp);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -