Beruflich Dokumente
Kultur Dokumente
Aim: To establish a connection between client and server using Transmission Control Protocol (TCP) and
User Datagram Protocol(UDP).
Algorithm:
Multicast:
1. When a client tries to join a group, distance vector routing tables are changed so that there is
spanning tree constructed for each group.
2. When Server tries to send a message to that particular group, this spanning is used to send the
message to all the clients subscribed to the group.
Broadcast:
1. When the server tries to broad cast a message to the clients in the network, the message is sent
using the broadcast address of the network.
Server:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public static void sendUDPMessage(String message,String ipAddress, int port) throws IOException {
DatagramSocket socket = new DatagramSocket();
InetAddress group = InetAddress.getByName(ipAddress);
byte[] msg = message.getBytes();
DatagramPacket packet = new DatagramPacket(msg, msg.length,
group, port);
socket.send(packet);
socket.close();
}
Client:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
@Override
public void run(){
try {
receiveUDPMessage("230.0.0.0", 4321);
}catch(IOException ex){
ex.printStackTrace();
}
}
}
Output:
Server:
Client:
Result:
Hence the JAVA program for multicasting and broadcasting using UDP has been implemented and the
output has been verified.
Experiment No: 5
Distance Vector Routing
Date: 13.09.2019
1. A router transmits its distance vector to each of its neighbors in a routing packet.
2. Each router receives and saves the most recently received distance vector from each of its
neighbors.
3. A router recalculates its distance vector when:
• It receives a distance vector from a neighbor containing different information than before.
• It discovers that a link to a neighbor has gone down.
Program:
#include<stdio.h>
#include<iostream>
using namespace std;
struct node
{
unsigned dist[6];
unsigned from[6];
}DVR[10];
int main()
{
cout<<"\n\n-------------------- Distance Vector Routing Algorithm----------- ";
int costmat[6][6];
int nodes, i, j, k;
cout<<"\n\n Enter the number of nodes : ";
cin>>nodes;
Output:
Result:
Hence the C++ program for distance vector routing has been implemented and the output has been
verified.