Professional Documents
Culture Documents
Winter Semester-2023-24
M.Tech. Software Engineering
SWE2002 - Computer Networks Lab Assessment – 3
Name: S. Daniel
Reg No: 22MIS0500
1. The finance office of VIT wishes to make the transactions more secure. If you are a
programmer how you will implement a system to validate the login credentials obtained
from the user thereby denying access to unauthorized users using UDP sockets? The
validity of the client must be sent as the reply message to the client and displayed it on
the standard output.
Code:
Server Side:
import java.net.*;
System.out.println("Server running...");
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData,
receiveData.length);
serverSocket.receive(receivePacket);
import java.net.*;
byte[] sendData;
byte[] receiveData = new byte[1024];
clientSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
2. Write a UDP program to implement an image transfer from client to server.
Server Side:
import java.io.*;
import java.net.*;
Client Side:
import java.io.*;
import java.net.*;
3. Find the physical address of a host when its logical address is known (ARP protocol)
using UDP.
import java.net.InetAddress;
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
4. Implement a DNS server and client using UDP sockets. The client should give the URL
as the input and the server should send the respective IP address.
Server Side:
import java.net.*;
while (true) {
byte[] receiveData = new byte[1024];
DatagramPacket receivePacket = new DatagramPacket(receiveData,
receiveData.length);
serverSocket.receive(receivePacket);
Client Side:
import java.net.*;
try {
DatagramSocket clientSocket = new DatagramSocket();
InetAddress serverAddress = InetAddress.getByName("localhost");
int serverPort = 9876;
clientSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
5. Implement a UDP-based socket program for the game “Guess It”. The game is played
by the client and server. The game proceeds as follows: The server will think of a “magic
number”. The magic number is greater than zero and less than 100. Prompt for the
“magic number” from the client. The server should print out “Higher” if the magic
number is higher than the guess and “Lower” if the magic number is less than the guess.
Give 10 chances for the client to guess the number. When the magic number has been
guessed print "Great" and then end. If the client cannot guess the number in 10 attempts,
then print the message "Better luck next time:)" and end.
Server Side:
import java.net.*;
if (i == 9) {
sendUDPMessage(serverSocket, clientAddress, clientPort, "Better luck next
time:)");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Client Side:
import java.net.*;
byte[] sendData;
byte[] receiveData = new byte[1024];
clientSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output: