Methods Summary |
---|
public java.net.InetAddress | getAddress()
return ia;
|
public int | getLocalPort()
return ds.getLocalPort();
|
public int | getPort()
return port;
|
public synchronized byte[] | receive()This method blocks until a UDP Datagram is received from the host with which
this UDPClient communicates. This can be an indefinite amount of time if
the host is unreachable so calls to this method should be placed in a separate
thread from the main program.
byte[] buffer = new byte[65507];
DatagramPacket incoming = new DatagramPacket(buffer, buffer.length);
ds.receive(incoming);
// a client should only receive data from the host to
while ( !incoming.getAddress().equals(ia)) {
ds.receive(incoming);
}
return incoming.getData();
|
public synchronized java.lang.String | receiveString()This method blocks until a UDP Datagram is received from the host with which
this UDPClient communicates. This can be an indefinite amount of time if
the host is unreachable so calls to this method should be placed in a separate
thread from the main program. When data is received it is
converted into an ISO-latin-1 String and returned.
byte[] data = receive();
return new String(data, 0, 0, data.length);
|
public void | send(byte[] buffer)This method sends data to the remote host via UDP. If the byte is longer than
the maximum reliable length of a UDP Datagram (64900) bytes then an
IOException is thrown
if (buffer.length > 64900) throw new IOException();
DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, port);
ds.send(dp);
|
public void | send(java.lang.String s)This method sends an ISO-Latin-1 string to the remote host via UDP.
The string will be truncated to ISO-Latin-1 even if it's Unicode.
byte[] data = new byte[s.length()];
s.getBytes(0, s.length(), data, 0);
send(data);
|
public void | send()This method sends an empty datagram to the remote host via UDP.
byte[] b = new byte[1];
send(b);
|
public java.lang.String | toString()
return ia + ":" + port;
|