there is a client that receives a byte [] stream. it is necessary to form separate arrays by parameters from it. this should all go in the receive mode packet Array format param1 = 1 byte param2 = 2nd byte param3 = 3rd byte param4 = 6th byte param5 = 7th byte

import java.net.*; import java.io.*; import java.util.ArrayList; import java.util.List; public class Client { public static void main(String[] ar) { int serverPort = 5050; // здесь обязательно нужно указать порт к которому привязывается сервер. String address = "127.0.0.1"; // это IP-адрес компьютера, где исполняется наша серверная программа. // Здесь указан адрес того самого компьютера где будет исполняться и клиент. try { Socket socket = new Socket(address, serverPort); byte[]s=read(socket); for(int i=0;i<s.length;i++){ System.out.println(s[i]); } /* OutputStream os = socket.getOutputStream(); //String str="hello"; DataOutputStream out1=new DataOutputStream(os); InputStream in = socket.getInputStream(); ArrayList <Integer> list=new ArrayList<>(); int value; int r; while( (r = in.read()) >= 0 ) { System.out.printf("%02X ", r); System.out.println(r); list.add(r); } */ } catch (Exception x) { x.printStackTrace(); } } static public byte[] read(Socket socket) throws IOException { byte[] array = new byte[280 * 1024]; int arrayPointer = 0; DataInputStream din = new DataInputStream(socket.getInputStream()); byte[] buffer = new byte[2048]; int readCount; while ((readCount = din.read(buffer)) != -1) { System.arraycopy(buffer, 0, array, arrayPointer, readCount); arrayPointer += readCount; } return array; } } 
  • 2
    Open the TCP / IP specification - everything is described there. Give an example of what you can not. - nick_n_a
  • I have already received a package but I need to break it into arrays - Andrei Kovalenko

0