V
V
Vanes Ri_Lax2015-08-04 12:52:45
Java
Vanes Ri_Lax, 2015-08-04 12:52:45

Why is the data not coming in completely?

hello, I'm implementing a client-server application.
I do everything according to the example here
. But for some reason, if data of 150 kilobytes in size is transmitted from the server, the data is not transferred to the end to the client, but for some reason in android studio in the console it becomes possible to enter data from the keyboard, what could be the reason?
sdfsdfk.jpg
1 data that did not come completely.
2 characters entered from the keyboard
Here is the client code:

import android.os.AsyncTask;
import android.util.Log;

import java.net.Socket;

public class Client {

    public static String command;
    AsyncClient asyncClient;

    public void setCommand(String command) {
        this.command = command;
        asyncClient = new AsyncClient();
        asyncClient.execute();
    }

    ////////////////////////////////////////////////////////
    class AsyncClient extends AsyncTask<Void, Void, Void> {

        Socket s;

        @Override
        protected void onPreExecute(){
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                s = new Socket("172.16.16.11",1122);
                //String msg = "hi server";
                s.getOutputStream().write(command.getBytes()); //посылаем команду на сервер
                byte[] buf = new byte[64*1024];
                int r = s.getInputStream().read(buf);
                String data = new String(buf,0,r); //строка от сервера

                Log.d("test", "Сообщение сервера: " + data);

                buf = new byte[500*1024];
                s.getOutputStream().write("ok".getBytes()); //говорим серверу что подтверждение полученно

                r = s.getInputStream().read(buf);
                //r = s.getInputStream().read();
                String xml = new String(buf,0,r); // принимаем большие данные
                Log.d("test",xml);


                s.close();
                s = null;
            }catch (Exception e){
                Log.d("test","Произошла ошибка: "+e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void resuld){
            super.onPostExecute(resuld);
        }
    }
}

Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-08-04
@gadfi

sorry that not much is not on the question, but why do you need sockets and other hardcore? why do all this by hand, you are waiting for xml at the entrance, so use retrofit and it is good friends with xml.
And if you write the server, read about REST and send json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question