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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With