This discussion is archived
5 Replies Latest reply: May 18, 2013 6:25 PM by EJP RSS

Unrecognized Windows Sockets Error: 0: JVM_Bind

795507 Newbie
Currently Being Moderated
I'm not entirely sure if I compacted this well enough, but after class declaration and method calling, it is essentially what my program does.
Server server = new Server(); // Creates a ServerSocket and binds it to a port.
Client client = new Client(server.getSocketAddress());
 
public Client(SocketAddress bind)
{
     try
     {
          socket = new Socket();
          socket.bind(bind); // Problem here
          recieve = new Scanner(socket.getInputStream());
          send = new Formatter(socket.getOutputStream());
     }
     catch (IOException e)
     {
          e.printStackTrace();
     }
}
Running the above code produces the following exception.
java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
     at java.net.PlainSocketImpl.socketBind(Native Method)
     at java.net.PlainSocketImpl.bind(Unknown Source)
     at java.net.Socket.bind(Unknown Source)
     at GameObjects.PlayArea$Client.<init>(PlayArea.java:318)
     at GameObjects.PlayArea.<init>(PlayArea.java:48)
     at MenuStates.GamePlayState.initializePlayArea(GamePlayState.java:90)
     at MenuStates.CreateGameState.mouseClicked(CreateGameState.java:106)
     at Manager.GameManager.mouseClicked(GameManager.java:428)
     at java.awt.Component.processMouseEvent(Unknown Source)
     at java.awt.Component.processEvent(Unknown Source)
     at java.awt.Container.processEvent(Unknown Source)
     at java.awt.Window.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Window.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
I don't even know what this exception is, and I can't find anything that will really tell me what is going on. Can anyone tell me what is happening here?

I know that this question isn't directly related to Game Development, but I am using it in a game program, and I posted this question in the Network forum, and they flooded my topic with useless messages, and the only person who actually answered my question was extremely vague about it, even after I asked him to clarify. I am hoping that the good people of this forum will be more helpful.
  • 1. Re: Unrecognized Windows Sockets Error: 0: JVM_Bind
    843853 Newbie
    Currently Being Moderated
    Step through with your debugger, I think you'll see that you have a 0 in your "bind" variable.
  • 2. Re: Unrecognized Windows Sockets Error: 0: JVM_Bind
    843853 Newbie
    Currently Being Moderated
    Ran into the same problem with one of my users. Google seems to suggest that it is a permissions issue when running in Windows 7. Are you running Windows 7? The suggestions I found are to run the application as an administrator, or disable UAC.

    Control Panels->Categories -> System & Security - >Review your systems status -> Change UAC settings -> Never notify me.
  • 3. Re: Unrecognized Windows Sockets Error: 0: JVM_Bind
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    robtaft wrote:
    Ran into the same problem with one of my users. Google seems to suggest that it is a permissions issue when running in Windows 7. Are you running Windows 7? The suggestions I found are to run the application as an administrator, or disable UAC.

    Control Panels->Categories -> System & Security - >Review your systems status -> Change UAC settings -> Never notify me.
    Running the app as admin is going to be safer than disabling UAC.
  • 4. Re: Unrecognized Windows Sockets Error: 0: JVM_Bind
    802491 Newbie
    Currently Being Moderated
    In some cases, the server socket used to need more time to be available. If you run several test, you need time to reuse the same port (for Windows 7). I could try the following code:
    Server server = new Server(); // Creates a ServerSocket and binds it to a port.
    Thread.sleep(500); // Waiting for server to be available
    Client client = new Client(server.getSocketAddress());
     
    public Client(SocketAddress bind)
    {
         try
         {
              socket = new Socket();
              socket.bind(bind); // Problem here
              recieve = new Scanner(socket.getInputStream());
              send = new Formatter(socket.getOutputStream());
              Thread.sleep(500); // Time to execute the sme port in another test.
         }
         catch (IOException e)
         {
              e.printStackTrace();
         }
    }
  • 5. Re: Unrecognized Windows Sockets Error: 0: JVM_Bind
    EJP Guru
    Currently Being Moderated
    I don't know how I missed this in 2010, but this is all nonsense.

    The actual problem here is that the OP is calling bind() when he should be calling connect(). He doesn't need to call bind() at all, and, if he does call bind(), it isn't valid to bind a socket to the same SocketAddress as any other socket.
    In some cases, the server socket used to need more time to be available.
    In what cases? I have never seen this in 16 years of Java. The methods concerned don't return until the socket and binding have been established. Adding random sleeps doesn't make code work, it just betrays lack of understanding, in my experience.