user2346809
user2346809

Reputation: 141

"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?

Upvotes: 14

Views: 55307

Answers (4)

java.nazif
java.nazif

Reputation: 733

You should change your port number. I had the same error. After I changed my port number, it resolved.

Upvotes: 4

neoneye
neoneye

Reputation: 52221

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.

Upvotes: 15

Eric Leschinski
Eric Leschinski

Reputation: 154063

Find out what program is using your port:

sudo netstat -nlp | grep 514

udp        0      0 :::514                :::*                            30186/java

Tells me that a java program is binding on UDP port 514

Upvotes: 3

Scary Wombat
Scary Wombat

Reputation: 44854

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.

Upvotes: 7

Related Questions