1

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);
    }
}
2
  • Sounds like an OS issue. Are you sure that the user that is running the JVM has enough OS permissions to bind to port 1500? Commented Oct 14, 2012 at 21:46
  • Are you sure 69.61.210.196 is an IP address of the local machine? And why not just bind to 0.0.0.0? Commented Oct 14, 2012 at 21:56

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.