/** Create a socket for sending UDP messages */
public void createSocket() {
try {
socket = new DatagramSocket();
public void sendPing(PingMessage ping) {
InetAddress host = ping.getHost();
int port = ping.getPort();
String message = ping.getContents();
try {
throw an exception to indicate that the socket timed out. This
can happen when a message was lost in the network. */
public PingMessage receivePing() throws SocketTimeoutException {
/* Create packet for receiving the reply */
byte recvBuf[] = new byte[MAX_PING_LEN];