The following should work (taken from Jt.InputStream component)
It uses read and a buffer. It also checks for maxLenght (which you
probably
don't need). Keep in mind that read may return less bytes than
requested.

At least something like this should give you an idea of what is
happening (exceptions,
log messages, etc)


       try {

            handleTrace ("readStream:available:" +
                    istream.available ());

            while ((len = istream.read (buf, 0, bufferSize)) > 0)
            {

                handleTrace ("readStream:" + len);
                buffer1 = new byte [len];

                i = 0;
                while (i < len) {
                    buffer1[i] = buf[i];
                    i++;
                }


                buff.setBuffer (buffer1);


                if (readStream) {

                    count += len;

                    if (count > maxLength) {
                        handleError ("maxLenth exceeded:" +
maxLength);
                        return (null);
                    }

                    if (sbuffer == null)
                        sbuffer = new StringBuffer ();

                    sbuffer.append(new String (buffer1));
                }
            }


        } catch (Exception e) {
            handleException (e);
            return (null);
        }

        return (sbuffer!=null?sbuffer.toString():null);

On Nov 13, 9:11 pm, bobetko <[email protected]> wrote:
> I am trying to write client for Android which is supposed to
> communicate with PC server application on local network.
> Server app is written by my friend in C#. Currently there is an iPhone
> app that is using this server application with no problems.
>
> I have very simple code for TCP client:
>
> 1. Socket s = new Socket(server, port);
> 2. OutputStream out = s.getOutputStream();
> 3. PrintWriter output = new PrintWriter(out);
> 4. output.println("ACTION=Next&VALUE=0&");
> 5. BufferedReader input = new BufferedReader(new
> InputStreamReader(s.getInputStream()));
> 6. String st = input.readLine();
>
> I went through many TCP implementation examples, and they are all
> similar. Pretty much like my code above.
> My app freezes on line 6 when I try to read response from the server.
> It doesn't cause any errors (no exceptions), nothing shows in
> debugger, just timeout error after awhile. Server is supposed to
> return string <OK> after executing my action in line 4.
> I don't understand why this code hangs. Input is not NULL (I've
> checked it). I would expect some exception to be thrown or simply
> empty string to be returned.
>
> So? What am I missing? Could it be problem with some special
> characters that server app is sending and android can't handle that?
> Do I need any special permission in my manifest?
>
> I am positive that I have correct IP address and correct port number.
> I can see that on server application running on my PC.
>
> Thanks.

-- 
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