62,635
社区成员




import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author huzhigang
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//监听3333端口
ServerSocket server=null;
Socket client = null;
Socket client2 = null;
try {
server = new ServerSocket();
server.setReuseAddress(true);
server.bind(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(),3333));
while(true){
client=new Socket();
client2 = new Socket();
client.setReuseAddress(true);
//绑定到3333端口
client.bind(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(),3333));
//连接9999端口
client2.setReuseAddress(true);
client2.bind(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(),3333));
client.close();
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}