Experiment 8
Experiment 8
Experiment 8
UDP Server:
import java.net.DatagramPacket;
import java.net.DatagramSocket;
try {
while (true) {
serverSocket.receive(receivePacket);
} catch (Exception e) {
e.printStackTrace();
UDP Client:
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
try {
// Create a DatagramSocket
InetAddress serverAddress =
InetAddress.getByName("localhost");
// Message to send
clientSocket.send(sendPacket);
clientSocket.close();
} catch (Exception e) {
e.printStackTrace();
OUTPUT:
Received message: Hello, UDP Server!
ANSHIKA SINGH (2100300130026)