📄 udpclient.java
字号:
// ==================== Program Discription ===================
// 程序名称:示例12-11: UDPClient.java
// 程序目的:创建UDP客户端
//=============================================================
import java.net.*;
import java.io.*;
public class UDPClient
{
public static void main(String args[])
{
try {
DatagramSocket sendSocket=new DatagramSocket(3456);
String string="asfdfdfggf";
byte[] databyte=new byte[100];
databyte=string.getBytes();
DatagramPacket sendPacket=new DatagramPacket(databyte,string.length(),
InetAddress.getByName("163.121.139.20"), 5000);
sendSocket.send(sendPacket);
System.out.println("send the data: hello ! this is the client");
}
catch (SocketException e) {
System.out.println("不能打开数据报Socket,或数据报Socket无法与指定的端口连接!");
}
catch(IOException ioe) {
System.out.println("网络通讯出现错误,问题在"+ioe.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -