简体   繁体   中英

java.net.BindException:JVM Bind

I keep running into this error: "Exception on new ServerSocket: java.net.BindException: Cannot assign requested address: JVM_Bind". I have tried using netstat to make sure that nothing is running on port(1500). Any advice?

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);
    }
}

It sounds like the IP address you are trying to bind to is your external IP address of the network and not your machine IP.

Recommend trying to bind to 127.0.0.1 or 0.0.0.0 instead.

To get your machine IP use from command line on windows ipconfig and on linux ifconfig .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM