[android-developers] Re: question on reading from socket in android ...

2010-01-18 Thread Marc Reichelt
Hi Antonio,

it would be much easier if you would provide a small piece of example
code. Otherwise we can only guess what your problem is.


Regards

Marc Reichelt   ||   http://www.marcreichelt.de/

On 18 Jan., 09:16, Antonio Si antonio...@gmail.com wrote:
 Hi,

 I have a background thread in my android client which sends a request
 to a server using a
 socket and then tries to read the data back from the socket.

 The data sending part works fine, but when I try to read from the
 inputStream of the socket,
 I am getting a EOFException.

 Any suggestions or advice would be highly appreciated.

 Thanks very much.

 Antonio.
-- 
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: question on reading from socket in android ...

2010-01-18 Thread Antonio Si
Hi Marc,

Thanks for your prompt response. Here is the code that I have:

  InetAddress addr = InetAddress.getByAddress(hostIp);
  socket = new Socket(addr, portNumber);
  socket.setKeepAlive(true);

  DataInputStream dis = new DataInputStream(new BufferedInputStream
(socket.getInputStream()));
  DataOutputStream dos = new DataOutputStream(new
BufferedOutputStream(socket.getOutputStream()));

  byte[] intBytes = convertToBytes(data.length);
  byte[] strMsgLengthBytes = convertToBytes(strMsgSize);
  dos.write(intBytes, 0, intBytes.length);
  dos.write(strMsgLengthBytes, 0, strMsgLengthBytes.length);
  dos.write(data, 0, data.length);
  dos.flush();

  ObjectInputStream ois = new ObjectInputStream(dis); // Here is
the place where an EOFException is being thrown
  ListResponseDataString returnObject =
(ListResponseDataString) ois.readObject();

In the above code, the line ois = new ObjectInputStream(dis); is the
place where an EOFException is being thrown.
In my server, I have checked that it has received the data
successfully. By the time the server tries to write to the
socket, the server is getting the following exception when it tries to
get an OutputStream from the socket:

java.net.SocketException: Socket is closed
at java.net.Socket.getOutputStream(Socket.java:814)

I would appreciate any advice.

Regards,

Antonio.


On Jan 18, 3:15 am, Marc Reichelt mcreich...@googlemail.com wrote:
 Hi Antonio,

 it would be much easier if you would provide a small piece of example
 code. Otherwise we can only guess what your problem is.

 Regards

 Marc Reichelt   ||  http://www.marcreichelt.de/

 On 18 Jan., 09:16, Antonio Si antonio...@gmail.com wrote: Hi,

  I have a background thread in my android client which sends a request
  to a server using a
  socket and then tries to read the data back from the socket.

  The data sending part works fine, but when I try to read from the
  inputStream of the socket,
  I am getting a EOFException.

  Any suggestions or advice would be highly appreciated.

  Thanks very much.

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