Neco asi podobneho jsem pred casem resil, pokud si dobre vypominam
reseni bylo jednak si podrobne precist javadoc k socket.getInputStream():
************************ kopirovano z javadoc ***************
Under abnormal conditions the underlying connection may be broken
by the remote host or the network software (for example a connection
reset in the case of TCP connections). When a broken connection is
detected by the network software the following applies to the returned
input stream:
* The network software may discard bytes that are buffered by
the socket. Bytes that aren't discarded by the network software can be
read using read.
* If there are no bytes buffered on the socket, or all buffered
bytes have been consumed by read, then all subsequent calls to read will
throw an IOException.
* If there are no bytes buffered on the socket, and the socket
has not been closed using close, then available will return 0.
**************************************************************
A taky bylo potreba pro socket nastavit jeho timeout, aby necekal vecne
pokud druha strana "potichu chcipne". Timeout socketu se nastavuje v
jeho metode connect(SocketAddress, int).
Mirek
Tomas Hubalek napsal(a):
Zdar,
mam takovy dotaz na java.net.Socket. Mam aplikaci, ktera posloucha na
nejakem portu, pokud prijde pozadavek, tak otevre Socket a prijima
pozadavky. Je tam nejaky InputStream, pres ktery ze ze Socketu cte.
Dokud chodi data, tak se zpracovavaji a jakmile prestanou, socket se
ukonci.
Neco jako
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while ((data = in.readLine()) != null) {
... zpracovavam data...
}
Mam totaz: Muze se stat, ze kdyz klient (co posila dtaa do socketu)
zdechne, tak ze mi to zustane zamrznute v readLine() ? Cekal bych
nejakou IOException....
Diky za jakekoliv info
Tom