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 | Description |
---|---|---|
static int |
DEFAULT_PORT |
The default echo port.
|
_isOpen_, _socket_, _socketFactory_, _timeout_
Constructor | Description |
---|---|
EchoUDPClient() |
Modifier and Type | Method | 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,
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 as
send(data, data.length, host) |
close, getCharset, getCharsetName, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeout, isOpen, open, open, open, setCharset, setDatagramSocketFactory, setDefaultTimeout, setSoTimeout
send
public static final int DEFAULT_PORT
public EchoUDPClient()
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.DiscardUDPClient.send(byte[], int, InetAddress, int)
public void send(byte[] data, java.net.InetAddress host) throws java.io.IOException
send(data, data.length, host)
send
in class DiscardUDPClient
data
- the buffer to sendhost
- the target hostjava.io.IOException
- if an error occursDiscardUDPClient.send(byte[], int, InetAddress, int)
public int receive(byte[] data, int length) throws java.io.IOException
data
- the buffer to receive the inputlength
- of the bufferjava.io.IOException
- If an error occurs while receiving the data.public int receive(byte[] data) throws java.io.IOException
receive(data, data.length)
data
- the buffer to receive the inputjava.io.IOException
- on error