public class UdpSend {
public static void main(String[] args) {
String content = "哇咔咔11111111111111111111";
String ip = "192.168.29.33";
int port = 1514;
DatagramSocket ds = null;
for(int i=0;i<10;i++){
try
{
ds = new DatagramSocket();
byte[] contents = content.getBytes("utf-8");
DatagramPacket packet = new DatagramPacket(contents,contents.length,
InetAddress.getByName(ip),port);
ds.send(packet);
System.out.println("==========发送成功============"+i);
}
catch(Exception ex){
System.out.println("==========发送失败============");
}
finally
{
if(null != ds)
ds.close();
}
}
}
}