Search code examples
javanetworkingntpproxies

how to pass through proxy in java


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..


Solution

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