[英]java.net.BindException:JVM Bind
我一直遇到此错误:“新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);
}
}
听起来您要绑定的IP地址是您网络的外部IP地址,而不是您的机器IP。
建议尝试改为绑定到127.0.0.1
或0.0.0.0
。
要在Windows ipconfig
和linux ifconfig
上从命令行使用机器IP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.