org.opengts.util
Class DatagramMessage

java.lang.Object
  extended by org.opengts.util.DatagramMessage

public class DatagramMessage
extends java.lang.Object

A class for sending and recieving datagram messages [CHECK]


Field Summary
protected  java.net.DatagramSocket datagramSocket
           
protected  java.net.DatagramPacket recvPacket
           
protected  java.net.DatagramPacket sendPacket
           
 
Constructor Summary
protected DatagramMessage()
          For subclassing only
  DatagramMessage(java.net.InetAddress destHost, int destPort)
          Constructor for sending messages
  DatagramMessage(java.net.InetAddress destHost, int destPort, int bindPort)
          Constructor for sending messages
  DatagramMessage(java.net.InetAddress destHost, int destPort, int bindPort, java.net.InetAddress bindAddr)
          Constructor for sending messages
  DatagramMessage(int port)
          Constructor for receiving messages
  DatagramMessage(java.lang.String destHost, int destPort)
          Constructor for sending messages
  DatagramMessage(java.lang.String destHost, int destPort, int bindPort)
          Constructor for sending messages
  DatagramMessage(java.lang.String destHost, int destPort, int bindPort, java.lang.String bindAddr)
          Constructor for sending messages
 
Method Summary
 void close()
          Closes the datagram socket
 java.net.DatagramPacket getReceivePacket()
          Gets the DatagramPacket last recieved [CHECK]
 java.net.DatagramPacket getSendPacket()
          Gets the datagram packet to be sent
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
 byte[] receive(int maxBuffSize)
          Receive an array of bytes
 void send(byte[] data)
          Send an array of bytes to the remote host
 void send(byte[] data, int len)
          Send an array of bytes to the remote host
 void send(byte[] data, int len, int count)
          Send an array of bytes to the remote host
 void send(java.lang.String msg)
          Send a String to the remote host
 void setRemoteHost(java.net.InetAddress host, int port)
          Set the remote(destination) host
 void setRemoteHost(java.lang.String host, int port)
          Set the remote(destination) host
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

datagramSocket

protected java.net.DatagramSocket datagramSocket

sendPacket

protected java.net.DatagramPacket sendPacket

recvPacket

protected java.net.DatagramPacket recvPacket
Constructor Detail

DatagramMessage

protected DatagramMessage()
For subclassing only


DatagramMessage

public DatagramMessage(int port)
                throws java.io.IOException,
                       java.net.UnknownHostException
Constructor for receiving messages

Parameters:
port - The port to use
Throws:
java.io.IOException - if a socket error occurs
java.net.UnknownHostException - if the IP adress of the host could not be determined

DatagramMessage

public DatagramMessage(java.lang.String destHost,
                       int destPort)
                throws java.io.IOException,
                       java.net.UnknownHostException
Constructor for sending messages

Parameters:
destHost - The remote(destination) host address
destPort - The remote(destination) port to use
Throws:
java.io.IOException - if a socket error occurs
java.net.UnknownHostException - if the IP adress of the host could not be determined

DatagramMessage

public DatagramMessage(java.net.InetAddress destHost,
                       int destPort)
                throws java.io.IOException
Constructor for sending messages

Parameters:
destHost - The remote(destination) host address
destPort - The remote(destination) port to use
Throws:
java.io.IOException - if a socket error occurs

DatagramMessage

public DatagramMessage(java.lang.String destHost,
                       int destPort,
                       int bindPort)
                throws java.io.IOException,
                       java.net.UnknownHostException
Constructor for sending messages

Parameters:
destHost - The remote(destination) host address
destPort - The remote(destination) port to use
bindPort - The local port to bind
Throws:
java.io.IOException - if a socket error occurs
java.net.UnknownHostException - if the IP adress of the host could not be determined

DatagramMessage

public DatagramMessage(java.lang.String destHost,
                       int destPort,
                       int bindPort,
                       java.lang.String bindAddr)
                throws java.io.IOException,
                       java.net.UnknownHostException
Constructor for sending messages

Parameters:
destHost - The remote(destination) host address
destPort - The remote(destination) port to use
bindPort - The local port to bind
bindAddr - The local address to bind
Throws:
java.io.IOException - if a socket error occurs
java.net.UnknownHostException - if the IP adress of the host could not be determined

DatagramMessage

public DatagramMessage(java.net.InetAddress destHost,
                       int destPort,
                       int bindPort)
                throws java.io.IOException
Constructor for sending messages

Parameters:
destHost - The remote(destination) host address
destPort - The remote(destination) port to use
bindPort - The local port to bind
Throws:
java.io.IOException - if a socket error occurs

DatagramMessage

public DatagramMessage(java.net.InetAddress destHost,
                       int destPort,
                       int bindPort,
                       java.net.InetAddress bindAddr)
                throws java.io.IOException
Constructor for sending messages

Parameters:
destHost - The remote(destination) host address
destPort - The remote(destination) port to use
bindPort - The local port to bind
bindAddr - The local address to bind
Throws:
java.io.IOException - if a socket error occurs
Method Detail

close

public void close()
           throws java.io.IOException
Closes the datagram socket

Throws:
java.io.IOException

setRemoteHost

public void setRemoteHost(java.lang.String host,
                          int port)
                   throws java.io.IOException
Set the remote(destination) host

Parameters:
host - The remote host address
port - The remote host port
Throws:
java.io.IOException - if an error occurs

setRemoteHost

public void setRemoteHost(java.net.InetAddress host,
                          int port)
                   throws java.io.IOException
Set the remote(destination) host

Parameters:
host - The remote host address
port - The remote host port
Throws:
java.io.IOException - if an error occurs

getSendPacket

public java.net.DatagramPacket getSendPacket()
Gets the datagram packet to be sent

Returns:
The datagram packet to be sent

send

public void send(java.lang.String msg)
          throws java.io.IOException
Send a String to the remote host

Parameters:
msg - The String to send to the remote host
Throws:
java.io.IOException - if the string is null or a socket error occurs

send

public void send(byte[] data)
          throws java.io.IOException
Send an array of bytes to the remote host

Parameters:
data - The array of bytes to send to the remote host
Throws:
java.io.IOException - if the string is null or a socket error occurs

send

public void send(byte[] data,
                 int len)
          throws java.io.IOException
Send an array of bytes to the remote host

Parameters:
data - The array of bytes to send to the remote host
len - The length of the data
Throws:
java.io.IOException - if the string is null or a socket error occurs

send

public void send(byte[] data,
                 int len,
                 int count)
          throws java.io.IOException
Send an array of bytes to the remote host

Parameters:
data - The array of bytes to send to the remote host
len - The length of the data
count - The number of times to send the message
Throws:
java.io.IOException - if the string is null or a socket error occurs

receive

public byte[] receive(int maxBuffSize)
               throws java.io.IOException
Receive an array of bytes

Parameters:
maxBuffSize - The maximum buffer size
Returns:
The recieved packet as a byte array
Throws:
java.io.IOException - if a socket error occurs

getReceivePacket

public java.net.DatagramPacket getReceivePacket()
Gets the DatagramPacket last recieved [CHECK]

Returns:
The DatagramPacket last recieved

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments