Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"java.net.BindException: Address already in use" when I am already running a service on the same port

I have one server socket program, when I run this program I get the following error:

java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
    at java.net.ServerSocket.bind(ServerSocket.java:328)
    at java.net.ServerSocket.<init>(ServerSocket.java:194)
    at Server.main(Server.java:20)
Could not listen on port: 5434.

A postgres sql server is already running on this port, which explains the error. My hardware device only sends data to this 5434 port.

What are my options to get around this error?

like image 744
user2346809 Avatar asked Dec 19 '13 07:12

user2346809


People also ask

What is Java net BindException?

java.net.BindException. Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned.

What is jvm_ bind?

Address already in use: JVM_Bind. means that some other application is already listening on the port your current application is trying to bind. what you need to do is, either change the port for your current application or better; just find out the already running application and kill it.

What went wrong Java net BindException address already in use Cannot bind?

it means that you are trying to use a port that is already open. check to see whether the port that you want to open is already open or not. also it may cause that your fireWall do not allows the application to listen on the port.


2 Answers

Mac specific

An instance of my java program was already running and occupying the port. So when I tried starting a new instance then I got the error. In order to kill the old instance I do the following:

prompt> lsof -i:5434
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    71107 neoneye   68u  IPv6 0x4a0371dea87d2cd3      0t0  TCP *:http-alt (LISTEN)
prompt> kill 71107

btw. I don't recommend stopping postgresql this way.

like image 152
neoneye Avatar answered Sep 18 '22 09:09

neoneye


If the port is being used by postgresql then you cant also open this port as a server port. Either shut postgresql down or use another port.

like image 43
Scary Wombat Avatar answered Sep 20 '22 09:09

Scary Wombat