Wednesday, 28 August 2013

Cant loopback Public IP to localhost

Cant loopback Public IP to localhost

This is my code snippet :
ServerSocket serverSocket = null;
Socket as = null;
try {
serverSocket = new ServerSocket(0, 5);
serverSocket.setSoTimeout(10000);
as = serverSocket.accept();
} catch (IOException e) {
System.out.println(e.getMessage());
}
//System.out.println(as.getInetAddress().getHostAddress());
Socket s = null;
try {
s = new Socket(serverSocket.getInetAddress(),
serverSocket.getLocalPort());
} catch (IOException e) {
System.out.println(e.getMessage());
}
try {
BufferedReader buff = new BufferedReader(new InputStreamReader(
s.getInputStream()), 8192);
while (true) {
String str = buff.readLine();
if (str == null) {
break;
}
System.out.println(str);
}
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
I just want to loop-back any request public IP address to 127.0.0.1.
Suppose if someone hits 49.138.xxx.xxx:port_num so this request will
loop-back to localhost (Android Hosted Webserver).
I simply want to bind localhost to my public IP address.
But whenever I run this code I am getting an error like Accept timed out

No comments:

Post a Comment