⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udp.java

📁 简单清晰具有启发性的实例。 Net1和Client1类实现了TCP的简单应用。 Udp和Udpwatch类实现了UDP的简单应用。 Chater是一个聊天小工具
💻 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 + -