Hi,
I am fairly new to the networking side of java, and I am stuck with something very straight forward. I can make a connection within my local network, but want to get my IP address so that a connection can be made externally.
I have the lines:
I am trying to get it so that I have a port and IP to be able to connect to this using telnet. At the moment at this very basic level all I require is to be able to send some commands over this connection.
The result of my code is:
( it has to listen on a random port because of networking issues we have here, that's no problem, I can manually enter that into telnet until that is fixed - Uni stuff ).
My IP is: 0.0.0.0
Listening on port: 52516
This is for part of my coursework, but I have tried, I do try, and I am a good student. It's only a tiny tiny part of a coursework. All I really need to work out is how to get my IP?
I can getLocalHost which will return my local IP, but of course that is no use outside of the network here.
Thanks!!
I am fairly new to the networking side of java, and I am stuck with something very straight forward. I can make a connection within my local network, but want to get my IP address so that a connection can be made externally.
I have the lines:
Code:
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(0);
System.out.println("My IP is: " + ServerSocket.getInetAddress().getHostAddress());
System.out.println("Listening on port: " + serverSocket.getLocalPort());
} catch (IOException e) {
System.err.println("Could not listen on port: PORT NAME");
System.exit(1);
}
}
I am trying to get it so that I have a port and IP to be able to connect to this using telnet. At the moment at this very basic level all I require is to be able to send some commands over this connection.
The result of my code is:
( it has to listen on a random port because of networking issues we have here, that's no problem, I can manually enter that into telnet until that is fixed - Uni stuff ).
My IP is: 0.0.0.0
Listening on port: 52516
This is for part of my coursework, but I have tried, I do try, and I am a good student. It's only a tiny tiny part of a coursework. All I really need to work out is how to get my IP?
I can getLocalHost which will return my local IP, but of course that is no use outside of the network here.
Thanks!!