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

有帮助吗?

解决方案

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

其他提示

  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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top