Hi All,
Please look at the following code:
import java.net.*;
import java.io.*;
public class WebReader {
public static void main(
String[] args) {
try {
java.util.Properties systemProperties = System.getProperties();
systemProperties.put("http.proxyHost","202.223.5.25");
systemProperties.put("http.proxyPort","4001");
Authenticator urlAuthenticator = new ProxyAuthenticator();
Authenticator.setDefault(urlAuthenticator);
Socket socket = new Socket("time.nist.gov", 13);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr);
reader.readLine(); // skip blank line
String message = reader.readLine();
System.out.println("WATCHOUT THIS "+message);
}catch(Exception e) {
e.printStackTrace();
}
}
}
class ProxyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("userName","password".toCharArray());
}
}
While executing i am getting Connection Time out Exception.
But if I use URLs the program works fine. Since i am inside proxy server i have implemented my own Authenticator so that it works fine and downloads the data from the Web when i use URLs but the same thing does not work when i use Sockets. What is the reason for this and how to overcome this? Please explain.
Thanks in Advance!!!
dinesh.