Results 1 to 5 of 5
  1. #1
    Sir_Fz is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default Client Socket Fails to Connect to ServerSocket

    I have a server socket listening on port 5077 and waiting for client connections
    Java Code:
    boolean listening = true;
    while (listening)
         new ServerThread(server.accept()).start();
    where ServerThread is a class extending Thread which processes the client connection.

    On the client side, I have the following:
    Java Code:
    System.out.println("Establishing connection");
    socket = new Socket(serverAddress, 5077);
    System.out.println("Get stream...");
    out = socket.getOutputStream();
    // the rest of the code here...
    When running the client, it only prints "Establishing connection" and stops there (it never connects) and throws no exceptions whatsoever. But when I try to use telnet on the client PC to the server address on port 5077 it works correctly which is completely strange. The client already works on other PCs, but on others it just freezes while telnet works.

    I've been trying to solve this for a while now but nothing worked, would be very kind if someone could point out what to do.

    Thank you.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    doesn't the way you have the ServerThread in the while loop as the single thread, only allow one client connection at a time ? (if someone else was connected at the time, no new client connect would work) ?

  3. #3
    Sir_Fz is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    No, each ServerThread is ran in a separate thread (the class extends Thread and has a custom run() method). Multiple connections already work with this server (tested).

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    are you trying to connect the client to server using public IP Address? if yes, then you have to use port forwarding...
    freedom exists in the world of ideas

  5. #5
    Sir_Fz is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    The issue has been solved. It seems the problem was with the proxy settings of the Internet Explorer on that PC. When I added the host of the server to the exception list, the client was able to connect (even though "by pass local addresses" was checked).

    But this is seriously a problem because before doing the above, the client wouldn't even recognize an invalid host. For example if I specify "askdsajk" as the host, it should atleast throw an unknown host exception but instead just hangs and never ends...

    Anyways, good thing I found the cause of the problem. Thanks to everybody :)

Similar Threads

  1. Replies: 3
    Last Post: 01-26-2009, 05:30 PM
  2. Server not able to connect client
    By Kapil Gupta in forum New To Java
    Replies: 15
    Last Post: 07-22-2008, 04:09 AM
  3. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 09:18 AM
  4. Replies: 1
    Last Post: 11-16-2007, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •