14

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?

Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
user2346809
  • 141
  • 1
  • 1
  • 3

4 Answers4

14

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.

neoneye
  • 44,507
  • 23
  • 155
  • 143
7

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.

Scary Wombat
  • 41,782
  • 5
  • 32
  • 62
  • Thanks, but hardware device is sending data to only postgres sql port, i've tried changing port no of postgres from 5432 to 5434. But device is unable to send it to 5432. i've changed hardware device port to 5434 now its running. – user2346809 Dec 19 '13 at 09:47
3

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

Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
2

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

rayryeng
  • 96,704
  • 21
  • 166
  • 177
java.nazif
  • 539
  • 1
  • 8
  • 17