No data available after sending data

Hello, I try to send and receive data over a Socket. After I send a command to the server, the server should return some data. However the check in.avaliable() always returns 0, while simply reading from the inputstream results in a recv error.

What am I doing wrong?

code

Socket clientSocket = new Socket("localhost",9100);

InputStream in = clientSocket.getInputStream();

OutputStream out = clientSocket.getOutputStream();

out.write(data);

out.flush();

int avail = in.available();

byte[] data = new byte[avail];

in.read(data);

[595 byte] By [rwklinka] at [2007-11-26 16:05:52]
# 1
available() and ready() don't do what you think they do - especially when connected to low bandwidth resources, like sockets. Don't use them. Use blocking calls to read() (or a variant of it), or NIO.
dannyyatesa at 2007-7-8 22:27:58 > top of Java-index,Core,Core APIs...