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?

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

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 4 Years Ago by ringo_tech

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.

what do you mean by:

Try creating just one server socket when the program starts

?

This article has been dead for over six months. Start a new discussion instead.