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?

Recommended Answers

All 6 Replies

Can you make a small, simple program that compiles, executes and shows the problem?

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

Can you post the code here on the forum?

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);
    }
}

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

?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.