public final class EchoUDPClient extends DiscardUDPClient
open
and call send
to send datagrams to the server,
then call receive
to receive echoes.
After you're done echoing data, call
close()
to clean up properly.
EchoTCPClient
,
DiscardUDPClient
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT
The default echo port.
|
_isOpen_, _socket_, _socketFactory_, _timeout_
Constructor and Description |
---|
EchoUDPClient() |
Modifier and Type | Method and Description |
---|---|
int |
receive(byte[] data)
Same as
receive(data, data.length) |
int |
receive(byte[] data,
int length)
Receives echoed data and returns its length.
|
void |
send(byte[] data,
java.net.InetAddress host)
Same as
send(data, data.length, host) |
void |
send(byte[] data,
int length,
java.net.InetAddress host)
Sends the specified data to the specified server at the default echo
port.
|
send
close, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeout, isOpen, open, open, open, setDatagramSocketFactory, setDefaultTimeout, setSoTimeout
public static final int DEFAULT_PORT
public void send(byte[] data, int length, java.net.InetAddress host) throws java.io.IOException
send
in class DiscardUDPClient
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.java.io.IOException
- If an error occurs during the datagram send
operation.public void send(byte[] data, java.net.InetAddress host) throws java.io.IOException
send(data, data.length, host)
send
in class DiscardUDPClient
java.io.IOException
public int receive(byte[] data, int length) throws java.io.IOException
java.io.IOException
- If an error occurs while receiving the data.public int receive(byte[] data) throws java.io.IOException
receive(data, data.length)
java.io.IOException