日期:2014-05-20 浏览次数:20803 次
final int LOCAL_PORT = 8880;
SocketAddress localAddr = new InetSocketAddress(LOCAL_PORT);
ServerSocket ss = new ServerSocket();
ss.setReuseAddress(true);
ss.bind(localAddr);
Socket socket = new Socket();
socket.setReuseAddress(true);
socket.bind(localAddr);
final String SERVER_IP = "";
final int SERVER_PORT = 60000;
SocketAddress serverAddr = new InetSocketAddress(SERVER_IP,SERVER_PORT);
socket.connect(serverAddr);
sendAndRegist(socket);
List<InetSocketAddress> addresses = receiveAndGetAddresses(socket);
createThreadToDoSomeThing(socket,addresses);
while(true){
Socket s = ss.accept();
createThreadToAccept(s);
}