0

Hi everbody,

in the server side of my project,when i close the socket then try to open it again the following exception is thrown

java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind

how to solve this without close the whole pogram to enable a client to reconnect to the server?

3
Contributors
6
Replies
9
Views
4 Years
Discussion Span
Last Post by ringo_tech
0

here is a simple program with simple GUI
when you press connect and a client get connected to the server then press disconnect
the exception will be thrown after the second connect button press

0

here are the codes of the connect and disconnect buttons

    private void connectMouseClicked(java.awt.event.MouseEvent evt) {                                     

    try{
        ServerSocket server=new ServerSocket(9000);
        sock=server.accept();
    }
    catch(Exception e){
        System.out.println(e);
    }
}                                    

private void disconnectMouseClicked(java.awt.event.MouseEvent evt) {                                        

    try{
        sock.close();
    }
    catch(Exception e){
        System.out.println(e);
    }
}

Edited by ringo_tech

0

Maybe you get the error because you try to create a second server socket the second time you click connect, but the port is still bound to the original server socket. Your code closes the (client) socket but not the server socket. Try creating just one server socket when the program starts.

0

what do you mean by:

Try creating just one server socket when the program starts

?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.