Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.8 kB
5
Indexable
    public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException {
        ServerSocket registerSocket = new ServerSocket(2121);
        String odpowiedz = null;
        boolean czyIstnieje;
        while (true) {
            Socket clientSocket = registerSocket.accept();
            PrintWriter ftoOut = new PrintWriter(clientSocket.getOutputStream(), true);
            BufferedReader ftoIn = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

            String[] odebrane = ftoIn.readLine().split("#|:");
            //  0          1         2     3       4          5             6        7    8      9   10    11   12     13
            //type:FileTransferOut#login:admin#filename:bazy_danych.ods#fileLength:401#packetNo:22#byteNo:401#content:0

            String login = odebrane[3];
            String fileName = odebrane[5];

            int fileLength = Integer.parseInt(odebrane[7]);
            int packetNo = Integer.parseInt(odebrane[9]);
            int packetSize = Integer.parseInt(odebrane[11]);

            byte[] newFile = new byte[fileLength];
            byte[] packet = new byte[1024];
            int actualByte = 0;
            int actualSize = 0;
            packet = contentToArray(odebrane[13],packetSize);


            do{
                //System.out.println(packetNo + " " + packetSize);
                actualByte = 0;
                if(packetNo == 1 ){

                    System.out.println("xD");
                    packet = contentToArray(odebrane[13],packetSize);
                    for (int i = actualSize; actualByte < packetSize; actualByte++) {
                        newFile[i] = packet[actualByte];
                        i++;
                        actualSize++;
                        System.out.println(actualSize + " " + fileLength);
                    }
                    packetNo++;
                    //ftoOut.println("Status:OK");
                    //ftoOut.flush();
                    System.out.println("xxx");
                }else{
                    System.out.println("dupa");
//                    String wiadomosc = ftoIn.readLine();
//                    System.out.println(wiadomosc);
                    odebrane = ftoIn.readLine().split("#|:");
                    System.out.println(odebrane[9]);
                    packet = contentToArray(odebrane[13],packetSize);
                    for (int i = actualSize; actualByte < packetSize; actualByte++) {
                        newFile[i] = packet[actualByte];
                        i++;
                        actualSize++;
                    }
                    System.out.println("dupa");
                    //ftoOut.println("Status:OK");

                }
            }while (actualSize <= fileLength);
        }
    }