betir
Class DatagramWrapper
java.lang.Object
|
+--betir.DatagramWrapper
- public class DatagramWrapper
- extends java.lang.Object
Wraps up the Datagram server communications at a higher level.
If the logfile argument to the constructor is not null, then
all communications sent and received are saved to the specified
file.
Constructor Summary |
DatagramWrapper(java.lang.String hostName,
int port,
int bufsize,
java.io.PrintWriter logger)
Opens a Datagram socket with the specified host, port, and buffer size. |
Method Summary |
void |
finalize()
Closes the network socket and log file if it exists. |
void |
println(java.lang.String line)
Allows classes with access to the DatagramWrapper to
print debugging messages to the logfile. |
java.lang.String |
receive()
Waits forever and receives a message from the server. |
java.lang.String |
receive(long wait)
Waits some time and receives a message from the server. |
void |
send(java.lang.String message)
Sends a message to the server. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DatagramWrapper
public DatagramWrapper(java.lang.String hostName,
int port,
int bufsize,
java.io.PrintWriter logger)
throws java.net.SocketException,
java.io.IOException
- Opens a Datagram socket with the specified host, port, and buffer size.
- Parameters:
hostName
- the name of the server to connect toport
- the port through which to connect to the host serverbufsize
- the size of the buffer to receive incomming communicationslogfile
- contains the name of the file to record all communications to.
If it is null, then no file is created.- Throws:
java.net.SocketException
- If there is an error connecting to the server.java.io.IOException
- If there is an error opening the file.
finalize
public void finalize()
- Closes the network socket and log file if it exists.
- Overrides:
finalize
in class java.lang.Object
send
public void send(java.lang.String message)
- Sends a message to the server.
Originally authored by Krzysztpf Langer and was distributed as
part of the Krislet code. Modifications have been made by PAB
to support the logging feature.
- Parameters:
message
- the message to be sent to the server
receive
public java.lang.String receive()
throws java.io.EOFException
- Waits forever and receives a message from the server.
- Returns:
- the message received from the server
receive
public java.lang.String receive(long wait)
throws java.io.InterruptedIOException,
java.io.EOFException
- Waits some time and receives a message from the server.
On timeout it throws an InterruptedIOException
- Parameters:
wait
- the number of milliseconds to wait before a timeout- Returns:
- the message received from the server, "" if there was a timeout.
println
public void println(java.lang.String line)
- Allows classes with access to the DatagramWrapper to
print debugging messages to the logfile.
- Parameters:
line
- text to send to the logfile