hello everyone!!!

I am currently working in socket programming in java and I am creating a simple chat application...

To go directly to my question,

ServerSocket server = new ServerSocket(1024);
Socket socket = server.accept();
String hostname = socket.getInetAddress().getHostName();
System.out.println(hostname);

If I will run my Server program, the output will be 0:0:0:0:0:0:0:1.
How can i interpret this? I want to print the hostname or the ip address of the client.

By the way, I am working in a localhost....

To print the IP address of a client use

System.out.println(clientSocket.getInetAddress().toString());

It will print the Ip address in this format /XXX.XXX.X.XX >>How can i interpret this?

It depends on what you want to do with the IP address or hostname.

If I will run my Server program, the output will be 0:0:0:0:0:0:0:1.

Is that an IPv6 address?

I ran your code and got

'localhost'

same with me too.Got local host only.

Is that an IPv6 address?

how can i determine that i am using a ipv6 address? and what version should be used?


please help... thanks

how can i determine that i am using a ipv6 address? and what version should be used?

IPv6 addresses look like 1080:0:0:0:8:800:200C:417A
IPv4 addresses look like 192.169.0.1

IPv4 is the current version, and universally available, but it's fast running out of addresses. IPv6 is the solution for the future, but it's rolling out very slowly, and not supported by many servers yet.

You should use whatever your network admin says. If you get your IP address automatically via DHCP you don't need to worry.

IPv6 addresses look like 1080:0:0:0:8:800:200C:417A
IPv4 addresses look like 192.169.0.1

IPv4 is the current version, and universally available, but it's fast running out of addresses. IPv6 is the solution for the future, but it's rolling out very slowly, and not supported by many servers yet.

You should use whatever your network admin says. If you get your IP address automatically via DHCP you don't need to worry.

thanks. So I know now that the output I receive is IPv6. But how I can set to IPv4, if i wanted to use this version?

Sorry man, that is as much as I know about IPv6! You'll need to find someone who knows more about it. When you do, please post what you find back here, so we can all learn. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.