smtp_relayserver
Class UDPClient

java.lang.Object
  |
  +--smtp_relayserver.UDPClient

public class UDPClient
extends java.lang.Object

This class allows you to send and receive Strings and byte arrays via UDP without concerning yourself with DatagramPackets and DatagramSockets.

Copyright (C) 1998 Valentin Koch

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


Constructor Summary
UDPClient(java.lang.String remoteHost, int port)
          Creates a new UDPClient.
 
Method Summary
 int getLocalPort()
           
 byte[] receive()
          This method blocks until a UDP Datagram is received from the host with which this UDPClient communicates.
 void send(byte[] buffer)
          This method sends data to the remote host via UDP.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPClient

public UDPClient(java.lang.String remoteHost,
                 int port)
          throws java.net.UnknownHostException,
                 java.net.SocketException
Creates a new UDPClient.
Parameters:
remoteHost - The domain name of the remote host to which data will be sent
port - The port on the remote host to which data will be sent
Throws:
java.net.UnknownHostException - The remoteHost is unknown
java.net.SocketException - En error occured by creating a DatagrammSocket
Method Detail

send

public void send(byte[] buffer)
          throws java.io.IOException
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
Parameters:
buffer - A byte array containing the data to be sent
Throws:
java.io.IOException - An error occured by sending the DatagrammPacket

receive

public byte[] receive()
               throws java.io.IOException
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.
Returns:
the data received as a byte array
Throws:
java.io.IOException - An error occured by receiving a DatagrammPacket

getLocalPort

public int getLocalPort()
Returns:
the port which this client is bound to