Reputation: 9785
I'm having trouble connecting a socket from my android phone to my computer running netcat listening on a port (5555).
What I run in my android app:
try {
Socket s = new Socket("My IP number here (not local IP)", 5555);
DataOutputStream outToServer = new DataOutputStream(s.getOutputStream());
outToServer.writeBytes("Hello!");
s.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
This is the line I use for netcat: nc -l 5555
I'm not sure what I'm missing.. I've forwarded the port on my router and rebooted the router. Added permission to internet in my android app. The phone is connected via 3G and my computer is connected via broadband. netcat is allowed in my firewall.
I get a SocketTimeoutException
error in my app when trying to connect.
I guess the router takes care of handling which computer in the LAN will receive the request.
Anyone know what I'm missing?
EDIT: I think I might have tracked down the problem.. I have two options on my router Virtual Server
and Port forwarding
. I don't know which to set to port 5555 in both UDP/TCP.
From what I understand it's
Virtual Server
I should use instead of the port forwarding? If so, could someone clarify the difference between the two?
Upvotes: 2
Views: 1785
Reputation: 9785
My computer had changed local IP since last configuration, so my Virtual Server
/Port Forwarding
rules did not apply, so I updated it (from 192.168.0.199 -> 192.168.0.196) and now it works excellently.
So all steps applied:
Virtual Server
/Port Forwarding
on your router .Inbound Filtering
on your router in case you wish to only allow a whitelisted IP to connect and propagate to next security layer. Upvotes: 1