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 49 50 public final class CharGenUDPClient extends DatagramSocketClient 51 { 52 53 public static final int SYSTAT_PORT = 11; 54 55 public static final int NETSTAT_PORT = 15; 56 57 public static final int QUOTE_OF_DAY_PORT = 17; 58 59 public static final int CHARGEN_PORT = 19; 60 61 public static final int DEFAULT_PORT = 19; 62 63 private byte[] __receiveData; 64 private DatagramPacket __receivePacket; 65 private DatagramPacket __sendPacket; 66 67 72 public CharGenUDPClient() 73 { 74 __receiveData = new byte[512]; 76 __receivePacket = new DatagramPacket (__receiveData, 512); 77 __sendPacket = new DatagramPacket (new byte[0], 0); 78 } 79 80 81 90 public void send(InetAddress host, int port) throws IOException 91 { 92 __sendPacket.setAddress(host); 93 __sendPacket.setPort(port); 94 _socket_.send(__sendPacket); 95 } 96 97 98 public void send(InetAddress host) throws IOException 99 { 100 send(host, DEFAULT_PORT); 101 } 102 103 111 public byte[] receive() throws IOException 112 { 113 int length; 114 byte[] result; 115 116 _socket_.receive(__receivePacket); 117 118 result = new byte[length = __receivePacket.getLength()]; 119 System.arraycopy(__receiveData, 0, result, 0, length); 120 121 return result; 122 } 123 124 } 125 126 | Popular Tags |