I am facing a problem in reading input stream in android application,
I am writing successfully in output stream but when i am reading input
stream i get a 0 value by available method. I executed same code in
j2se successfully in java. my code is as follows:

output.writeInt(json.length());
                        output.writeBytes(json);
                        output.flush();

                        System.out.println(json);
                        int iBlockingTimeMS = 500;
                        int avail; //number of available bytes in input stream
                        while(true)
                        {

                                try {
                                        avail=input.available();
                                        if (avail<=0) {
                                                //active waiting:
                                                input.read(new byte[0]);
                                                Thread.sleep( iBlockingTimeMS );
                                        }
                                        else
                                                break;
                                } catch (InterruptedException e) {}
                        }
                        //retry after active waiting

                        byte arr[]=new byte[avail];
                        int read=input.read(arr);
                        System.out.println(json);
                        String response=new String(arr);
                        response=response.substring(response.indexOf('{'));
                        JSONObject 
responseInJson=JSONObject.fromObject(response);
                        double returnedID=responseInJson.getDouble("result");


can anyone suggest me solution of this problem.
thanks in advance

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to