blue ink is what i did please ignore that ystemtelose books/notes) Problem 1 (20
ID: 3725935 • Letter: B
Question
blue ink is what i did please ignore that
ystemtelose books/notes) Problem 1 (20 points) Two processes P1 and P2 use the Java datagram socket AP (IPC) between them. T network and systems involved. In each of the following time-event diag already been I for interprocess communication here is no timeout set on either side and there is no failure on the ram, P1 and P2 have running, neither P1 nor P2 has issued any send or receive operation prior to the operations shown in the diagram, and neither P1 nor P2 issues any additional send or receive operation afterwards. Complete each diagram to strate the blocking and/or unblocking of each process subsequent to the issuance of the operations - be sure to indicate whena process is unblocked. Each send operation issued by P1 is to to P2, and vice versa. The diagrams are independent of each otherExplanation / Answer
Socket:
An attachment is an endpoint for correspondence between two unique machines. An application program can send/get messages from an attachment. Every attachment has a port related with it.
Attachment Programming in java is utilized for entomb process correspondence between two procedures (programs) running in two distinct machines. There are two fundamental conventions can be accustomed to transmitting the message.
1.) TCP/IP - Connection-Oriented Protocol
2.) UDP - Connection-less Protocol (You have to send the sender address for each bundle transmitted).
Using User Datagram Protocol, Applications can send data/message to the other hosts without prior communications or channel or path. This means even if the destination host is not available, application can send data. There is no guarantee that the data is received in the other side. Hence it's not a reliable service.
UDP is appropriate in places where delivery of data doesn't matters during data transition.
In this section, Let us see how to implement a simple Client Server UDP Communication using Datagram Sockets.
UDPServer Implementation
package in.techdive.udp.server;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class UDPServer
{
public static void main(String args[])
{
int server_port = 1111;
System.out.println("UDP Server Listening in " + server_port);
try
{
DatagramSocket socket = new DatagramSocket(server_port);
byte[] msgBuffer = new byte[1024];
DatagramPacket packet = new DatagramPacket(msgBuffer, msgBuffer.length);
while (true)
{
socket.receive(packet);
String message = new String(msgBuffer, 0, packet.getLength());
System.out.println("UDPServer: Message received = " + message);
packet.setLength(msgBuffer.length);
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Error in getting the Data from UDP Client");
}
}
}
UDPClient Implementation
package in.techdive.udp.server;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class UDPClient
{
public static void main(String args[])
{
try
{
String server_address = "localhost";
int server_port = 1111;
String message = "Techdive.in";
InetAddress address = InetAddress.getByName(server_address);
DatagramPacket packet = new DatagramPacket(message.getBytes(), message.getBytes().length, address, server_port);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
System.out.println("UDPClient: Sent data to Server ; Message = " + message);
socket.close();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Error in sending the Data to UDP Server");
}
}
}
Testing
With a specific end goal to test the above UDP Client and Server, play out the underneath steps,
1. Execute the UDPServer.java class.
This will make the Datagram Socket and it will listen ceaselessly in the port 1111.
2. Execute the UDPClient.java class which will send the information utilizing Datagram Socket to the nearby host in port 1111.
OUTPUT
UDP Server Listening in 1111
UDPServer: Message got = Techdive.in
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.