Advertisement
Eternoseeker

Serverside Selective repeat

Apr 17th, 2023 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | Source Code | 0 0
  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.IOException;
  4. import java.net.ServerSocket;
  5. import java.net.Socket;
  6. import java.net.SocketException;
  7.  
  8. public class servers {
  9.     static ServerSocket Serversocket;
  10.     static DataInputStream dis;
  11.     static DataOutputStream dos;
  12.  
  13.     public static void main(String[] args) throws SocketException {
  14.         try {
  15.             int a[] = { 30, 40, 50, 60, 70, 80, 90, 100 };
  16.             Serversocket = new ServerSocket(8011);
  17.             System.out.println("waiting for connection");
  18.             Socket client = Serversocket.accept();
  19.             dis = new DataInputStream(client.getInputStream());
  20.             dos = new DataOutputStream(client.getOutputStream());
  21.             System.out.println("The number of packets sent is:" + a.length);
  22.             int y = a.length;
  23.             dos.write(y);
  24.             dos.flush();
  25.             for (int i = 0; i < a.length; i++) {
  26.                 dos.write(a[i]);
  27.                 dos.flush();
  28.             }
  29.             int k = dis.read();
  30.             dos.write(a[k]);
  31.             dos.flush();
  32.         }
  33.         catch (IOException e){
  34.             System.out.println(e);
  35.         }
  36.         finally{
  37.             try{
  38.                 dis.close();
  39.                 dos.close();
  40.             }
  41.             catch (IOException e){
  42.                 e.printStackTrace();
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement