com.oroinc.net
Class EchoUDPClient
java.lang.Object
|
+--com.oroinc.net.DatagramSocketClient
|
+--com.oroinc.net.DiscardUDPClient
|
+--com.oroinc.net.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
with 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.
- Author:
- Daniel F. Savarese
- See Also:
EchoTCPClient
,
DiscardUDPClient
Field Summary |
static int |
DEFAULT_PORT
The default echo port. |
Method Summary |
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. |
Methods inherited from class com.oroinc.net.DatagramSocketClient |
close, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeout, isOpen, open, open, open, setDatagramSocketFactory, setDefaultTimeout, setSoTimeout |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_PORT
public static final int DEFAULT_PORT
- The default echo port. It is set to 7 according to RFC 862.
EchoUDPClient
public EchoUDPClient()
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 class DiscardUDPClient
- 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.
send
public void send(byte[] data,
java.net.InetAddress host)
throws java.io.IOException
- Same as
send(data, data.length, host)
- Overrides:
send
in class DiscardUDPClient
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.
- 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 as
receive(data, data.length)
Copyright © 1997-2002 Daniel F. Savarese. All Rights Reserved.