Advertisement
Eternoseeker

selectiveclient

Jun 7th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | Source Code | 0 0
  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.IOException;
  4. import java.net.Socket;
  5.  
  6. public class selectiveclient {
  7.     public static void main(String[] args) throws IOException {
  8.         Socket s = new Socket("localhost", 3333);
  9.         DataInputStream din = new DataInputStream(s.getInputStream());
  10.         DataOutputStream dout = new DataOutputStream(s.getOutputStream());
  11.         int y = din.read();
  12.         System.out.println();
  13.         int[] arr = new int[y];
  14.         for (int i = 0; i < y; i++) {
  15.             arr[i] = din.read();
  16.             System.out.println("Receiving frame: " + arr[i]);
  17.         }
  18.         arr[4] = -1;
  19.         int temp = 0;
  20.         for (int i = 0; i < y; i++) {
  21.             if (arr[i] == -1) {
  22.                 temp = i;
  23.                 System.out.println("Error in frame: " + arr[i]);
  24.             } else {
  25.                 System.out.println("Receiving frame:" + arr[i]);
  26.             }
  27.         }
  28.         dout.write(temp);
  29.         arr[temp] = din.read();
  30.         System.out.println("resent frame:" + temp);
  31.         System.out.println("final frame");
  32.         System.out.println(arr[temp]);
  33.         din.close();
  34.         s.close();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement