Computer Networking Lab Manual-1-Pages-Deleted
Computer Networking Lab Manual-1-Pages-Deleted
5a
Program for Address Resolution Protocol (ARP)
Aim : To write a java program for simulating ARP protocols using TCP
ALGORITHM:
Client
1. Start the program
2. Using socket connection is established between client and server.
3. Get the IP address to be converted into MAC address.
4. Send this IP address to server.
5. Server returns the MAC address to client.
Server
1. Start the program
2. Accept the socket which is created by the client.
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the IP address which is send by the client.
5. Map the IP address with its MAC address and return the MAC address to client.
Program
Client:
import java.io.*;
import java.net.*;
public class Clientarp {
public static void main(String[] args) {
try {
// Create a socket to connect to the server on localhost and port 8080
Socket socket = new Socket("localhost", 8080);
// Get the input and output streams for communication
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
// Prompt the user to enter the logical address (IP)
System.out.print("Enter the Logical address (IP): ");
String ipAddress = userInput.readLine();
// Send the IP address to the server
out.writeBytes(ipAddress + "\n");
Resut: Thus the ARP protocol using TCP Sockets program was executed.
Exp. No. 5b
Program for Reverse Address Resolution Protocol (RARP)
Aim:
To write a java program for simulating RARP protocols using UDP
ALGORITHM
Client
Server
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
public static void main(String args[])
{
try {
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
{
public static void main(String args[])
{
try
{
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
{
if(s.equals(mac[i]))
sendbyte=ip[i].getBytes();
DatagramPacket sender-new DatagramPacket(sendbyte,sendbyte.length, addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch (Exception e)
System.out.println(e);
{
}
}
}
Output:
I:\ex>java Serverrarp12
I:\ex>java Clientrarp12