DC 9225 Exp5
DC 9225 Exp5
5
Practical No:
Evaluation:
Theory:
Group communication is a paradigm for multi-party communication that is based
on the notion of groups as a main abstraction. A group is a set of parties that,
presumably,want to exchange information in a reliable, consistent manner. For
example:
• The participants of a message-based conferencing tool may constitute a group.
Ideally, in order to have meaningful communication, each participant wants to
receive all communicated messages from each other participant. Moreover, if one
message isa response to another, the original message should be delivered before
the response.(In this example, if two participants originate messages independently
at about the same time, the order in which such independent messages are
delivered is not important)
• The set of replicas of a fault-tolerant database server may constitute a group.
Consider updating messages to the server. Since the contents of the database
depend on the history of all update messages received, all updates must be
delivered to all replicas. Furthermore, all updates must be delivered in the same
order. Otherwise, inconsistencies may arise.
Group Communication Primitives
Group communication is implemented using middleware that provides two sets of
primitives to the application:
● Multicast primitive (e.g., post): This primitive allows a sender to post a message
to the entire group.
● Membership primitives (e.g., join, leave, query_membership): These primitives
allow a process to join or leave a particular group, as well as to query the group for
the list of all current participants.
Three types of group communication:
● One to many (single sender and multiple receivers)
In this scheme, there are multiple receivers for a message sent by a single sender.
The one-to-many scheme is also known as multicast communication. A special
case of multicast communication is broadcast communication, in which the
message is sent to all processors connected to a network.
● Many to one (multiple senders and single receiver)
➔ Multiple senders send messages to a single receiver.
➔ The single receiver may be selective or nonselective.
Server.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
while (true) {
Socket clientSocket = serverSocket.accept();
System.out.println("Client connected from: " +
clientSocket.getInetAddress().getHostAddress());
clientSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Client.java
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
while (true) {
System.out.print("Enter message (or 'exit' to quit): ");
String message = scanner.nextLine();
if (message.equalsIgnoreCase("exit")) {
break;
}
writer.println(message);
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Output:
Multi :
Steps to run the Multi Client Server Communication application
1. Start Server program. It will be ready to accept connections from the
Master.
2. On another terminal start the Master program followed by the Slave and
send some message from the Master to the Slave.
3. Multiple Slaves can be started to depict group communication.
Server.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;
import java.util.Set;
while (true) {
Socket clientSocket = serverSocket.accept();
clients.add(clientSocket);
System.out.println("New client connected: " +
clientSocket);
MasterClient.java
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;
while (true) {
System.out.print("Enter message to send to slaves (or
'exit' to quit): ");
String message = scanner.nextLine();
if (message.equalsIgnoreCase("exit")) {
break;
}
outputStream.write(message.getBytes());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
SlaveClient.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
while (true) {
String message = reader.readLine();
if (message == null) {
break;
}
System.out.println("Received message from server: " +
message);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Output:
Conclusions :
1. Implemented group communication using Java.
2. Understood and learnt the three types of group communication.
Postlab Questions:
1.Explain group communication.
Group communication, also known as multicast communication, refers to the
process of transmitting data from one sender to multiple receivers simultaneously
within a network. In group communication, the sender sends a single message, and
the message is received by all members of the group who are interested in
receiving it.
3. Broadcast Communication:
- In broadcast communication, a single sender transmits a message to multiple
receivers simultaneously.
- All receivers receive the same message, and there is no interaction or exchange
of messages between receivers.
- Broadcast communication is commonly used in scenarios such as broadcasting
television and radio programs, public announcements, and multicast messaging in
computer networks.