我总是遇到这样的错误:“新的ServerSocket异常: java.net.BindException:无法分配请求的地址: JVM_Bind”。我尝试使用netstat来确保没有任何东西在端口(1500)上运行。有什么建议吗?
package server;
import java.io.IOException
import java.net.InetAddress
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class Server
{
private ServerSocket serverSocket;
Server(int Port)
{
/* create socket server and wait for connection requests */
try
{
serverSocket = new ServerSocket(1500, 0, InetAddress.getByName("69.61.210.196"));
System.out.println("Server waiting for client on port " + serverSocket.getLocalPort());
while(true)
{
Socket socket = serverSocket.accept(); // accept connection
System.out.println("New client asked for a connection");
}
}
catch (IOException e)
{
System.out.println("Exception on new ServerSocket: " + e);
}
}
public static void main(String[] args)
{
new Server(1500);
}
}发布于 2012-10-15 07:35:53
听起来,您尝试绑定的IP地址是网络的外部IP地址,而不是您的机器IP。
建议尝试绑定到127.0.0.1或0.0.0.0。
在windows ipconfig和linux ifconfig上从命令行获取你的机器IP地址。
https://stackoverflow.com/questions/12886765
复制相似问题