Beruflich Dokumente
Kultur Dokumente
Important: When sending the PING-PONG message, be careful to send it on the socket address from where the
datagram came. See the method getSocketAddress from DatagramPacket class.
Example dialog
client->broadcast PING
server->client PONG
client->server PING-PONG
Server Source
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
socket.send(responseDatagram);
System.out.println("PONG -> " + clientAddr.getHostAddress());
} else if (request.startsWith("PING-PONG")) {
System.out.println("ESTABLISHED <-> " + clientAddr.getHostAddress());
}
}
}
}