Program in Java to execute a simple connectionless communication between a server and client.
There are two types of protocol in the transport layer for communication:
In UDP (User Datagram Protocol), a connection is not formed online in TCP where the client sends a request to the server for a connection. The message is sent in the form of a datagram packet. Datagrams upon arrival contain the address of the sender which the server uses to send data to the correct client.
The algorithm for the whole process is:
1) Create a UDP socket-
2) Read request-
3) Write reply-
serverSocket.sent(reply packet, host, port);
4) Continue to read request.
1) Create Datagram Socket for client-
2) Send request-
3) Read reply-
UDP advantages and disadvantages:
1) It is faster than TCP
2) Not reliable is a connection is not formed
3) No acknowledgment when the message is received.
1) DatagramPacket(byte buff, int length)
2) DatagramPacket(byte buff, int length, InetAddress address, int port)
## byte format is used to send or receive.
Java representation of address-
1) InetAddress address = InetAddressgetByName("nameofthesite.com");
2) InetAddress address = InetAddress.getLocalHost();
Simplex Communication is one-way communication. It means that messages can be sent from one side and received from the other.
This is the implementation of simplex communication.
To run the program, first, run the server code then the client code.
Submitted by Purnima Agarwal (Purnima)
Download packets of source code on Coders Packet