Question

In: Computer Science

Write a Java program for slidsender and slidreiver 1. Start the program 2. Get the frame...

Write a Java program for slidsender and slidreiver

1. Start the program

2. Get the frame size from the user

3. To create the frame based on the user

4. To send frames to server from the client

5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to

6. Stop the program

Solutions

Expert Solution

Program code for slidsender :

---------------------------------------

---------------------------------------

import java.net.*;
import java.io.*;
import java.rmi.*;
public class slidsender
{
public static void main(String a[]) throws Exception
{
ServerSocket ser=new ServerSocket(1024);
Socket s=ser.accept();
DataInputStream in=new DataInputStream(System.in);
DataInputStream in1=new DataInputStream(s.getInputStream());
String sbuff[]=new String[8];
PrintStream p;
int sptr=0,sws=8,nf,ano,i;
String ch;
do
   {
   p=new PrintStream(s.getOutputStream());
   System.out.print("Enter the no. of frames : ");
   nf=Integer.parseInt(in.readLine());
   p.println(nf);
   if(nf<=sws-1) {
       System.out.println("Enter "+nf+" Messages to be send\n");
       for(i=1;i<=nf;i++) {
               sbuff[sptr]=in.readLine();
              p.println(sbuff[sptr]);
               sptr=++sptr%8;} sws-=nf;
               System.out.print("Acknowledgment received");
               ano=Integer.parseInt(in1.readLine());
               System.out.println(" for "+ano+" frames"); sws+=nf;
    } else
        {
       System.out.println("The no. of frames exceeds window size");
       break;
   }
   System.out.print("\nDo you wants to send some more frames : ");
   ch=in.readLine();
   p.println(ch);
}
while(ch.equals("yes"));
s.close();
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Program code for slidreceiver :

---------------------------------------

---------------------------------------


import java.net.*;
import java.io.*;
class slidreceiver
{
public static void main(String a[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),1024);
DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
int i=0,rptr=-1,nf,rws=8;
String rbuf[]=new String[8];
String ch;
System.out.println();
do
    {
   nf=Integer.parseInt(in.readLine());
    if(nf<=rws-1)
        {
        for(i=1;i<=nf;i++)
           {
           rptr=++rptr%8;
           rbuf[rptr]=in.readLine();
           System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
           }
       rws=nf;
       System.out.println("\nAcknowledgment sent\n");
       p.println(rptr+1);
       rws+=nf;
       }
   else {
       break;
   }
   ch=in.readLine();
   }
   while(ch.equals("yes"));
   }
}


Related Solutions

Write a complete java program to get input of a person’s age and their years of...
Write a complete java program to get input of a person’s age and their years of current USA citizenship. Tell them if they are eligible to run for US House of Representatives, US Senate, or President. At first, have the program just run once and give the answer for the given inputs. Give the answer in a nice format and be clear which offices the person can run for. Write good and complete pseudo code. Next, put that program in...
Write a complete java program to get input of a person’s age and their years of...
Write a complete java program to get input of a person’s age and their years of current USA citizenship. Tell them if they are eligible to run for US House of Representatives, US Senate, or President. At first, have the program just run once and give the answer for the given inputs. Give the answer in a nice format and be clear which offices the person can run for. Write good and complete pseudo code. Next, put that program in...
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
Write a JAVA program that emulates a Magic Eight Ball. Start by generating a random number...
Write a JAVA program that emulates a Magic Eight Ball. Start by generating a random number and then use a switch statement to display the message. Use this website as a resource on possible answers a Magic Eight Ball gives: https://en.wikipedia.org/wiki/Magic_8-Ball
In Java Write a program that allows Professor Poindexter to get class averages including the average...
In Java Write a program that allows Professor Poindexter to get class averages including the average for allher/his classes. Professor Poindexter has M classes. M will be input from the terminal. For each class he/she will input each student’s grade for that class until 0 is input. Once the goof prof inputs 0, The class average for that class is output in the form:   Average for Class X 1 is XXX.XX Finally, once all the M class data is input,...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
Directions 1. Start up IDLE3.8 and open a scripting window. 2. Write a program to solve...
Directions 1. Start up IDLE3.8 and open a scripting window. 2. Write a program to solve the following problem: functions - The program should input 3 integers, do calculations and print results. You need to write 4 functions for average, smallest, largest and middle as well as writing a main(). Use the main() for input, calling functions and output. Enter a number...6 Enter a number...2 Enter a number...11 Average = 6.33 Smallest = 2 Largest = 11 Numbers in order...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT