我正在尝试构建一个java微博应用程序我已经完成了代码但由于以下错误无法连接到我自己的计算机(我谷歌它并且有人说我需要更改端口号。我更改了端口号并且没有任何反应)
Exception in thread "Thread-4" java.net.BindException: Address already in use: JVM_Bind
下面是服务器的代码:
public class server extends Thread {
public Socket client = null;
public ServerSocket server = null;
private int port = 4444;
public void run(){
while (true){ //loop waits for incomming connection
try { //start the server and listen to a port
server = new ServerSocket(port);
}catch (IOException e){
System.err.println(e);
System.exit(-1);
}
try { //establish a connection when receiving request
client = server.accept();
}catch (IOException e){
System.err.println(e);
System.exit(1);
}
Thread t = new Thread(new Connection(client));
t.start();
}
}
}
这是启动服务器并监听端口 4444 的代码
Server server = new Server();
server.start(); //to listen to a port
谢谢