Question

i want my java code to send and receive response from ntp server. however, since i am behind a proxy i am unable to receive any response. how do i access the server response through the proxy? i am using the following code, but it is no helping me much.

    System.setProperty("http.proxySet", "true");
    System.setProperty("http.proxyHost", "107.108.85.10");
    System.setProperty("http.proxyPort", "80");

please help.

    socket.send(packet);
    System.out.println("NTP request sent, waiting for response...\n");
    packet = new DatagramPacket(buf, buf.length);
    socket.receive(packet);
    System.out.println("Packet Received");

I am able to see the NTP request sent, waiting for response... ,but not the packet received response..

Was it helpful?

Solution

DatagramPacket means UDP. HTTP proxies can only proxy HTTP requests, so you're out of luck. Try googling 'NTP over HTTP'.

OTHER TIPS

  1. System.setProperty("http.proxySet", "true") does nothing.

  2. System.setProperty("http.proxyHost", "107.108.85.10") and System.setProperty("http.proxyPort", "80") do exactly what you want as long as you are using HTTP URLs. They do nothing if you are using Sockets directly.

  3. If you have an HTTP proxy the implication is that you are using the HTTP protocol, in which case you should use the classes provided in Java for the purpose. Or third-party APIs such as the Apache HttpClient which has its own way of defining the proxy.

  4. If you aren't using HTTP, an HTTP proxy isn't going to be much use to you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top