Advertisement
Eternoseeker

selectiveserver

Jun 7th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | Source Code | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class selectiveserver {
  5.     public static void main(String[] args) throws IOException {
  6.         ServerSocket ss = new ServerSocket(3333);
  7.         Socket s = ss.accept();
  8.         DataInputStream din = new DataInputStream(s.getInputStream());
  9.         DataOutputStream dout = new DataOutputStream(s.getOutputStream());
  10.         int[] arr = { 10, 20, 30, 40, 50, 60, 70 };
  11.         int k = arr.length;
  12.         dout.write(k);
  13.         for (int i = 0; i < arr.length; i++) {
  14.             System.out.println("sending frame:" + arr[i]);
  15.             dout.write(arr[i]);
  16.         }
  17.         int rd = din.read();
  18.         System.out.println("ERROR frame recieved aft ack" + (rd + 1));
  19.         dout.write(arr[rd]);
  20.         din.close();
  21.         s.close();
  22.         ss.close();
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement