[android-developers] Re: BufferedReader hangs on readline

2011-09-12 Thread petter


On Sep 12, 12:45 am, Nick Risaro nris...@gmail.com wrote:
 On Sun, Sep 11, 2011 at 5:54 PM, petter petter.gus...@gmail.com wrote:
  Are end of line characters handled differently in Android?

 Probably, the EoL is encoding dependent. Try forcing the encoding to
 something like UTF-8 in both ends of the socket.

It's probably related to eol detection.

I tried UTF-8 on the android side, but it did not change anything. The
response is all ASCII.

I can't control the server since it's a hardware device where I have
no ability to log in.

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


[android-developers] Re: BufferedReader hangs on readline

2011-09-11 Thread petter
Are the end of line characters treated differently?

It seem to work fine if I use


char[] buf = new char[8192];



On Sep 11, 7:14 pm, petter petter.gus...@gmail.com wrote:
 I'm trying to read a response from a server and
 BufferedReader.readline will block and never return.

 If I run the exact same code from the command line on my Linux host it
 works, but it will hang when run on my emulator or device.

 Here's the code

         try {
             System.out.println(will call socket!);
             mysocket = new Socket(hostname, portno);
             System.out.println(Connected to  +
 mysocket.getInetAddress() +  on port 
                                + mysocket.getPort() +  from port  +
 mysocket.getLocalPort() +  of 
                                + mysocket.getLocalAddress());

             DataOutputStream os = new
 DataOutputStream(mysocket.getOutputStream());
             DataInputStream is = new
 DataInputStream(mysocket.getInputStream());

             BufferedReader d = new BufferedReader(new
 InputStreamReader(is));

             if (mysocket != null  os != null  is != null) {
                 os.writeBytes(command + \r\n);
                 String line;
                 System.out.println(calling readline after command: + 
 command);
                 line = d.readLine();
                 System.out.println(got:  + line);
                 return line;
             }
         }
         catch (UnknownHostException e) {
 ...

 What I see on android is:

 I/System.out(  644): will call socket!
 I/System.out(  644): Connected to /192.168.1.109 on port 4998 from
 port 52695 of /10.0.2.15
 I/global  (  644): Default buffer size used in BufferedReader
 constructor. It would be better to be explicit if an 8k-char buffer is
 required.
 I/System.out(  644): calling readline after command:getversion
 D/dalvikvm(   98): GC freed 2313 objects / 133904 bytes in 67ms
 W/KeyCharacterMap(  644): No keyboard for id 0
 W/KeyCharacterMap(  644): Using default keymap: /system/usr/keychars/
 qwerty.kcm.

 On Linux (OpenJDK) I get what I expect:

 Connected to /192.168.1.109 on port 4998 from port 33097 of /
 192.168.1.104
 calling readline after command:getversion
 got: 710-1001-04
 getversion returned: 710-1001-04

 Any ideas? Is the BufferedReader different on Android?

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


[android-developers] Re: BufferedReader hangs on readline

2011-09-11 Thread petter
It seem to work if I use read instead of readline like:


char[] buf = new char[8192];
int charsRead;
charsRead = d.read(buf,0,buf.length);

Are end of line characters handled differently in Android?


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


Re: [android-developers] Re: BufferedReader hangs on readline

2011-09-11 Thread Nick Risaro
On Sun, Sep 11, 2011 at 5:54 PM, petter petter.gus...@gmail.com wrote:

 Are end of line characters handled differently in Android?


Probably, the EoL is encoding dependent. Try forcing the encoding to
something like UTF-8 in both ends of the socket.

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