• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in reading input stream from a socket

 
jitendra kumar sharma
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a socket to a linux machine on my local network, socket is created and connected successfully, then I have created one DataInputStream and one DataOutputStream by socket. writing a byte array and length of byte array to output stream and then flush output stream. But when I try to read input stream it is blocked due to no data is available in input stream, I check this by available() method.

However, I connected to this socket in iphone and flex successfully, can anyone suggest me what should i do to resolve this.

thanks in advance.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Available doesn't do what you think it does
 
jitendra kumar sharma
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved this problem,
but when i tried my code in android application, I am getting same error, my code as follows:
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags. I've added them for you this time.

I see you still use available(). Why? If you want to use non-blocking I/O check out SocketChannel in combination with a Selector instead.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic