- The frame is sent one-by-one to the Receiver(Server) from the Sender(Client) side.
- Acknowledgment is sent from Server to the Client
- The next frame is sent after receiving the acknowledgment from the server-side.
Stop-and-wait ARQ: (source: wiki)
- Stop and Wait Protocol also referred to as alternating bit protocol, is a method in telecommunications to send information between two connected devices.
- It ensures that information is not lost due to dropped packets and that packets are received in the correct order. It is the simplest automatic repeat-request (ARQ) mechanism.
- A stop-and-wait ARQ sender sends one frame at a time; it is a special case of the general sliding window protocol with transmitting and receiving window sizes equal to one and greater than one respectively.
- After sending each frame, the sender doesn't send any further frames until it receives an acknowledgment (ACK) signal.
- After receiving a valid frame, the receiver sends an ACK. If the ACK does not reach the sender before a certain time, known as the timeout, the sender sends the same frame again.
- The timeout countdown is reset after each frame transmission.
- The above behavior is a basic example of Stop-and-Wait.
- However, real-life implementations vary to address certain issues of design.
Program Coding:
RECEIVER(SERVER)
import java.io.*;
import java.net.*;
import java.util.*;
/**
*
* @author StarkeeCode
*/
public class receiver {
public static void main(String args[])
{
String h="Serverhost";
int q=5000;
int i;
try
{
ServerSocket ss2;
ss2 = new ServerSocket(8000);
Socket s1 =ss2.accept();
DataInputStream dd1= new DataInputStream(s1.getInputStream());
Integer i1 =dd1.read();
for(i=0;i<i1;i++)
{
ServerSocket ss1;
ss1 = new ServerSocket(9000+i);
Socket s =ss1.accept();
DataInputStream dd= new DataInputStream(s.getInputStream());
String sss1 = dd.readUTF();
System.out.println(sss1);
System.out.println("Frame "+ i+" received");
DataOutputStream d1 = new DataOutputStream(s.getOutputStream());
d1.write(i);
System.out.println("ACK sent for "+ i);
}
}
catch(Exception ex)
{
System.out.println("Error"+ex);
}
}
}
SENDER(CLIENT)
import java.io.*;
import java.net.*;
import java.util.Scanner;
/**
*
* @author StarkeeCode
*/
public class sender {
public static void main(String args[])
{
int p=9000,i,q=8000;
String h="localhost";
try
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of frames : ");
int number = scanner.nextInt();
if(number==0)
{
System.out.println("No frame is sent");
}
else
{
Socket s2;
s2= new Socket(h,q);
DataOutputStream d1 = new DataOutputStream(s2.getOutputStream());
d1.write(number);
}
String str1;
for (i=0;i<number;i++)
{
System.out.print("Enter message : ");
String name = scanner.next();
System.out.println("Frame " + i+" is sent");
Socket s1;
s1= new Socket(h,p+i);
DataOutputStream d = new DataOutputStream(s1.getOutputStream());
d.writeUTF(name);
DataInputStream dd= new DataInputStream(s1.getInputStream());
Integer sss1 = dd.read();
System.out.println("Ack for :" + sss1 + " is received");
}
}
catch(Exception ex)
{
System.out.println("ERROR :"+ex);
}
}
}
Output:
3 Comments
Can you please explain what is q in sender and receiver and why their values are 8000 and 5000?
ReplyDeleteq and p are just variables to hold the portal id (5000,8000) for sending the data between the protocols
Delete1xbet korean | Is 1xbet korean a good option? | Legalbet.co.kr
ReplyDelete1xbet korean. 1xbet korean. 1xbet korean. 1xbet korean. 1xbet korean. 1xbet korean. 1xbet korean. 1xbet 1xbet korean korean. 1xbet korean. 카지노사이트 1xbet 메리트 카지노 주소 korean.