Sliding Window Protocol in Java | StarkeeCode

Sliding window protocol can be implemented in Java using two different classes in the same packages using a unique id.

Sliding window protocols are used to deliver in-order packets in Transmission Control Protocol (TCP) and Data link layer and it is also a feature of packet-based data transmission protocols.

Detail:

The socket is an endpoint of the two-way communication link between two programs running on the same network and the programs communicate with each other using the port running port numbers on the network. Here, the client and server are the two programs using the socket for transferring data.

Advantage:

  • Sliding window protocol is efficient than the Stop and Wait protocol.
  • Sliding window protocol sends multiple frames and retransmits damaged frames.

"STOP AND WAIT PROTOCOL" 

which transfers single frames at a time and waits for acknowledgment from the receiver before sending the next frame.

Explanation:

The client and server programs are two different java classes in the same package "server-client". Both programs must be deployed in a try-catch block to handle exceptions.

 In the Client class, the "port address" is used to connect the server (9000), and the message is given in the WriteUTF method(build-in) used to send data to another end program. 

In the Server class, the value for port address is given (9000) [like an identity to connect the server], and the ReadUTF method(build-in) is used to receive any message from the client-side and the message is displayed.

[NOTE: Run the server class first to open a socket connection with a port number, then run the client class]

Program Coding:

SERVER:
import java.io.*;
import java.net.*;
public class server {
public static void main(String args[])
{
try
{
ServerSocket ss1;
ss1 = new ServerSocket(9000);
Socket s =ss1.accept();
DataInputStream dd= new DataInputStream(s.getInputStream());
String sss1 = dd.readUTF();
System.out.println(sss1);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
--------------------------------
CLIENT:
import java.io.*;
import java.net.*;
public class client {
public static void main(String args[])
{
String h="localhost";
int p=9000;
try
{
Socket s1;
s1= new Socket(h,p);
DataOutputStream d = new DataOutputStream(s1.getOutputStream());
d.writeUTF("Start server :");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}


Output:

server class output
Server class 
client class output 
Client class

Reactions

Post a Comment

3 Comments

  1. Gold Country Casino Buffet Prices - Casinofib 우리카지노 우리카지노 gioco digitale gioco digitale william hill william hill 167Wynn Hotel Group Limited - Legalbet.co.KR

    ReplyDelete
  2. Happy Luke Bet | Betting Offers for Horse Racing & Football
    Get the latest betting offers rb88 for Horse Racing & Football, including happyluke latest Promotions, Bet Builder & Live Scores. ミスティーノ T&Cs apply.

    ReplyDelete
  3. Lucky Club Casino site, profile picture - Lucky Club
    Lucky Club Casino is the gambling site owned by the same owner. The company has several hundred employees and includes many employees working luckyclub in the business. This

    ReplyDelete