chiradee chiradee - 8 months ago 51
Java Question Address already in use: JVM_Bind error while trying to close a listener

I'm getting a Address already in use: JVM_Bind
error when I'm trying to close a listener. Here's my code in opening the listener.

SMPPServerSessionListener sessionListener = new SMPPServerSessionListener(newPort);

and here is my code closing it.

public String getCloseConn() throws IOException{
System.out.println("porttt: " + newPort);
SMPPServerSessionListener sess = new SMPPServerSessionListener(newPort);

return "";

What my program does is ask the user for port number and start it on submit. Then I'm trying to close the listener when the user click the "Stop Server" button triggering the
method but I'm getting the error I mentioned earlier. Help please.
PS: Please don't be harsh on me I'm just new here :)


You should not be calling

SMPPServerSessionListener sess = new SMPPServerSessionListener(newPort); 

expecting to get the existing listener. That statement attempts to create a NEW listener, on the same port as the existing listener, which results in the error you are seeing.

You should pass in a reference to the existing session to the close method and close that instead.