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 38 39 public final class EchoUDPClient extends DiscardUDPClient 40 { 41 42 public static final int DEFAULT_PORT = 7; 43 44 private DatagramPacket __receivePacket = new DatagramPacket (new byte[0], 0); 45 46 57 public void send(byte[] data, int length, InetAddress host) 58 throws IOException 59 { 60 send(data, length, host, DEFAULT_PORT); 61 } 62 63 64 65 public void send(byte[] data, InetAddress host) throws IOException 66 { 67 send(data, data.length, host, DEFAULT_PORT); 68 } 69 70 71 80 public int receive(byte[] data, int length) throws IOException 81 { 82 __receivePacket.setData(data); 83 __receivePacket.setLength(length); 84 _socket_.receive(__receivePacket); 85 return __receivePacket.getLength(); 86 } 87 88 89 public int receive(byte[] data) throws IOException 90 { 91 return receive(data, data.length); 92 } 93 94 } 95 96 | Popular Tags |