aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes problem in reading input stream from a socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "problem in reading input stream from a socket" Watch "problem in reading input stream from a socket" New topic
Author

problem in reading input stream from a socket

jitendra kumar sharma
Greenhorn

Joined: Dec 30, 2009
Posts: 2
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

Available doesn't do what you think it does


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jitendra kumar sharma
Greenhorn

Joined: Dec 30, 2009
Posts: 2
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in reading input stream from a socket
 
Similar Threads
Java 1.3 Socket Input Stream
File Transfer in Java Using Sockets
XML mapping rules
how to send a file or photo to clients using sockets??
Want Help Reagarding Reading Text