Rojee
Rojee

Reputation: 43

Java ServerSocket won't accept request from remote client connected via LAN Cable

I have created a Server using java.net sockets, I try accessing it via localhost client and it is accepting the requests and responding to client, but when I try accessing it remotely from another computer via LAN cable connection, it doesn't accept any connection even though it is listening to the local port (9999), then to see if the port does not work I configured Apache Web Server to listen to port (9999) and it does work, so I set it to listen to a different port but no luck and tried opening various ports on the firewall still doesn't work.

Can someone please explain to me why the Server does not accept requests or establish connection from remote client?

ServerSocket:

try {
    Server = new ServerSocket(L_port);  
}
catch(IOException e) {
}

while(!runServer) {
    try {
        incoming = Server.accept();
        InputStream client;


        //Create the 2 threads for the incoming and outgoing traffic of proxy server
        outgoing = new Socket(R_host, R_port); 

        proxyThread thread1 = new proxyThread(incoming, outgoing);
        thread1.start();

        proxyThread thread2 = new proxyThread(outgoing, incoming);
        thread2.start();
    } 
    catch (UnknownHostException e) {

    } 
    catch(IOException e){

    }
}

nestat -an:

enter image description here

Upvotes: 2

Views: 1489

Answers (1)

user207421
user207421

Reputation: 311023

Clearly you have bound the socket to 127.0.0.1, which only allows connections from the localhost, instead of 0.0.0.0, which would allow them from anywhere.

Upvotes: 1

Related Questions