我有发送端,没写出来,补上
public class Sender {
/**
* @param args
* @throws Exception
* @throws SocketException
*/
public static void main(String[] args) throws SocketException, Exception {
Scanner sc = new Scanner(System.in);
DatagramSocket socket = new DatagramSocket();
while(true){
String s = sc.nextLine();
//创建DatagramSocket,绑定本机端口和地址
//创建DatagramPacket,指定数据,长度,对方的IP和端口
DatagramPacket packet = new DatagramPacket(s.getBytes(), s.getBytes().length, InetAddress.getByName("1-pc"), 20000);
//发送出去
socket.send(packet);
}
}
}
就是打印不出来 |