1

i have been trying to write some programs on java sockets and i got stuck with this problem. Normally the INetAddress object is created using the factory methods getLocalHost(), getbyAddress(byte[]) and getbyName(string).... when I use getbyName function...

for example...

INetAddress a=InetAddress.getbyName("www.google.com"); 

and trying to print the above object using println method i was getting Unknown host exception but actually i heard that it would perform a DNS query and return one of the IP address of a server of google.com but its not working that way... i used netbeans to run the program and our college has a proxy server also.

One more thing... if i use the getbyName(string) and give an argument as some others PC name who is within the college network then can it resolve the system IP address ? . In my case this was unable to resolve.. I checked by turning the windows firewall to off state also but in vain.... please help...

ping www.google.com is showing "ping request could not find the host name google.com"

7
  • Socket can just take a host as a port in the constructor. so, you can just do Socket s = new Socket("www.google.com", 80); this will probably result in the same problem - if your dns is not configured properly. Commented Feb 29, 2012 at 14:01
  • What do you get if you do a ping www.google.com Commented Feb 29, 2012 at 14:04
  • its showing "ping request could not find the host name google.com" Commented Feb 29, 2012 at 14:07
  • How to configure the DNS..?? im using windows 7 premium... and also will it resolve the system names in the same network... for example... getbyName("example-PC"); will it give the IP address of the system?? Commented Feb 29, 2012 at 14:15
  • 1
    There is your answer, it's a networking issue, nothing to do with your code. Commented Feb 29, 2012 at 14:37

1 Answer 1

2

The name resolution strategy used by InetAddress.getByName depends on the operating system. If the OS is configured to use DNS to resolve names, that's what InetAddress.getByName will use. (Probably.)

To check that DNS is working correctly you can run nslookup www.google.com from a terminal.

One more thing... if i use the getbyName(string) and give an argument as some others PC name who is within the college network then can it resolve the system IP address ?

If other programs on your system can resolve the name to an IP address so should Java.

Sign up to request clarification or add additional context in comments.

3 Comments

You say that ping cannot find the host name. That should tell you it's not using DNS, or that your DNS servers don't know about google.com. Either way it looks like you need to use a proxy if you want to connect to the internet.
actually our college uses proxy server... so is that the problem for this... if i connect directly through a packet data connection will i get a change in the result??
Of course. When you connect through a proxy your machine doesn't resolve the host name. It just tells the proxy "please connect to this machine and make this request for me".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.