Showing posts with label STOP AND WAIT PROTOCOL. Show all posts
Showing posts with label STOP AND WAIT PROTOCOL. Show all posts

Friday, October 25, 2013

TO IMPLEMENT STOP AND WAIT PROTOCOL IN JAVA

/*
TOPIC:TO IMPLEMENT STOP AND WAIT PROTOCOL
FILENAME:slisender.java
*/
import java.io.*;
import java.net.*;
class slisender
{
public static void main(String aafhbasgj[])throws Exception
{
ServerSocket ss=new ServerSocket(6483);
Socket s=ss.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DataInputStream in=new DataInputStream(s.getInputStream());
String msg,str1;
PrintStream p;
int no;
p=new PrintStream(s.getOutputStream());
System.out.println("Enter number of frames");
no=Integer.parseInt(br.readLine());
p.println(no);
int i=0;
while(i<no)
{
System.out.println("enter ur frame :");
msg=br.readLine();
p.println(msg);
str1=in.readLine();
System.out.println(str1);
i++;
}
ss.close();
s.close();
}
}
/*
TOPIC:TO IMPLEMENT STOP AND WAIT PROTOCOL
FILENAME: sliclient.java
*/
import java.io.*;
import java.net.*;
class sliclient
{
public static void main(String aafhbasgj[])throws Exception
{

Socket s=new Socket("localhost",6483);
String opmsg;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream dos=new PrintStream(s.getOutputStream());
String msg=in.readLine();
int no=Integer.parseInt(msg);
int i=0;
while(i<no)
{
msg=in.readLine();
System.out.println(msg);
opmsg="ACK : FRAME "+i+" RECIEVED";
dos.println(opmsg);
i++;
}
s.close();
}
}