Package org.apache.commons.net.echo
Class EchoUDPClient
- java.lang.Object
-
- org.apache.commons.net.DatagramSocketClient
-
- org.apache.commons.net.discard.DiscardUDPClient
-
- org.apache.commons.net.echo.EchoUDPClient
-
public final class EchoUDPClient extends DiscardUDPClient
The EchoUDPClient class is a UDP implementation of a client for the Echo protocol described in RFC 862. To use the class, just open a local UDP port withopen
and callsend
to send datagrams to the server, then callreceive
to receive echoes. After you're done echoing data, callclose()
to clean up properly.- See Also:
EchoTCPClient
,DiscardUDPClient
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PORT
The default echo port.-
Fields inherited from class org.apache.commons.net.DatagramSocketClient
_isOpen_, _socket_, _socketFactory_, _timeout_
-
-
Constructor Summary
Constructors Constructor Description EchoUDPClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
receive(byte[] data)
Same asreceive(data, data.length)
int
receive(byte[] data, int length)
Receives echoed data and returns its length.void
send(byte[] data, int length, java.net.InetAddress host)
Sends the specified data to the specified server at the default echo port.void
send(byte[] data, java.net.InetAddress host)
Same assend(data, data.length, host)
-
Methods inherited from class org.apache.commons.net.discard.DiscardUDPClient
send
-
Methods inherited from class org.apache.commons.net.DatagramSocketClient
close, getCharset, getCharsetName, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeout, isOpen, open, open, open, setCharset, setDatagramSocketFactory, setDefaultTimeout, setSoTimeout
-
-
-
-
Field Detail
-
DEFAULT_PORT
public static final int DEFAULT_PORT
The default echo port. It is set to 7 according to RFC 862.- See Also:
- Constant Field Values
-
-
Method Detail
-
send
public void send(byte[] data, int length, java.net.InetAddress host) throws java.io.IOException
Sends the specified data to the specified server at the default echo port.- Overrides:
send
in classDiscardUDPClient
- Parameters:
data
- The echo data to send.length
- The length of the data to send. Should be less than or equal to the length of the data byte array.host
- The address of the server.- Throws:
java.io.IOException
- If an error occurs during the datagram send operation.- See Also:
DiscardUDPClient.send(byte[], int, InetAddress, int)
-
send
public void send(byte[] data, java.net.InetAddress host) throws java.io.IOException
Same assend(data, data.length, host)
- Overrides:
send
in classDiscardUDPClient
- Parameters:
data
- the buffer to sendhost
- the target host- Throws:
java.io.IOException
- if an error occurs- See Also:
DiscardUDPClient.send(byte[], int, InetAddress, int)
-
receive
public int receive(byte[] data, int length) throws java.io.IOException
Receives echoed data and returns its length. The data may be divided up among multiple datagrams, requiring multiple calls to receive. Also, the UDP packets will not necessarily arrive in the same order they were sent.- Parameters:
data
- the buffer to receive the inputlength
- of the buffer- Returns:
- Length of actual data received.
- Throws:
java.io.IOException
- If an error occurs while receiving the data.
-
receive
public int receive(byte[] data) throws java.io.IOException
Same asreceive(data, data.length)
- Parameters:
data
- the buffer to receive the input- Returns:
- the number of bytes
- Throws:
java.io.IOException
- on error
-
-