This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes how to resolve java.net.BindException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how to resolve java.net.BindException" Watch "how to resolve java.net.BindException" New topic
Author

how to resolve java.net.BindException

Binesh Veetil
Greenhorn

Joined: Jan 21, 2012
Posts: 9
I am trying to create a new ServerSocket object and I am getting the following error:
java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)

Code to create server socket is as follows:
server = new ServerSocket(port, 0, hostInetAddress);

Please help me resolve this.
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
Binesh Veetil wrote:I am trying to create a new ServerSocket object and I am getting the following error:
java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)

Code to create server socket is as follows:
server = new ServerSocket(port, 0, hostInetAddress);

Please help me resolve this.



The issue is simple. A process is already bound to the port in questions. Are you on a linux box or a window box?

Cheers,
Philip
Binesh Veetil
Greenhorn

Joined: Jan 21, 2012
Posts: 9
Philip Thamaravelil wrote:

The issue is simple. A process is already bound to the port in questions. Are you on a linux box or a window box?

Cheers,
Philip


I am on linux box.
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
Binesh Veetil wrote:
Philip Thamaravelil wrote:

The issue is simple. A process is already bound to the port in questions. Are you on a linux box or a window box?

Cheers,
Philip


I am on linux box.




so, to determine what process id is running on your port, run:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Philip Thamaravelil wrote:The issue is simple. A process is already bound to the port in questions.

Not necessarily. On Linux and Unix regular users cannot open ports below 1024. You need root access for that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Binesh Veetil
Greenhorn

Joined: Jan 21, 2012
Posts: 9
Rob Spoor wrote:Not necessarily. On Linux and Unix regular users cannot open ports below 1024. You need root access for that.

What do you mean by root access? Will I be able to do a telnet from IP to another like : <telnet IP Port> port numbers which I am using are below 1024 as well.
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
Binesh Veetil wrote:
Rob Spoor wrote:Not necessarily. On Linux and Unix regular users cannot open ports below 1024. You need root access for that.

What do you mean by root access? Will I be able to do a telnet from IP to another like : <telnet IP Port> port numbers which I am using are below 1024 as well.



telenet'ing to another machine is completely unrelated to your ability to bind a process to a port on the local machine.

In your post, you mentioned your trying to start an application that will bind and listen on port XXXX. Rob makes a great point, that you either need to select a port number > 1024 OR you must run the process as the user root. IMO, your better off selecting a higher numbered port as your less likely to run into port conflicts with another process.

Cheers,
Philip
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Binesh Veetil wrote:
Rob Spoor wrote:Not necessarily. On Linux and Unix regular users cannot open ports below 1024. You need root access for that.

What do you mean by root access? Will I be able to do a telnet from IP to another like : <telnet IP Port> port numbers which I am using are below 1024 as well.

Connecting to a port with a client is allowed for any user. Otherwise you couldn't even browse the web. The 1024 limitation only exists for listening to incoming connections.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to resolve java.net.BindException
 
Similar Threads
java application to listen on port 80.
Closing a serversocket gracefully...
File trasfer between machines
all ports are used-adress already in use
Reset ServerSocket