1 16 package org.apache.commons.net; 17 18 import java.io.IOException ; 19 import java.net.DatagramPacket ; 20 import java.net.InetAddress ; 21 22 40 41 public final class DaytimeUDPClient extends DatagramSocketClient 42 { 43 44 public static final int DEFAULT_PORT = 13; 45 46 private byte[] __dummyData = new byte[1]; 47 private byte[] __timeData = new byte[256]; 49 50 59 public String getTime(InetAddress host, int port) throws IOException 60 { 61 DatagramPacket sendPacket, receivePacket; 62 63 sendPacket = 64 new DatagramPacket (__dummyData, __dummyData.length, host, port); 65 receivePacket = new DatagramPacket (__timeData, __timeData.length); 66 67 _socket_.send(sendPacket); 68 _socket_.receive(receivePacket); 69 70 return new String (receivePacket.getData(), 0, receivePacket.getLength()); 71 } 72 73 74 public String getTime(InetAddress host) throws IOException 75 { 76 return getTime(host, DEFAULT_PORT); 77 } 78 79 } 80 81 | Popular Tags |