# sockets (security)



## mischka (13. Apr 2004)

hi,

in my thread which handles the handshake for incoming client connections i am using the following code:

```
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
String myQuery = reader.readLine();
```
readLine() blocks until it hits a termination like \n or the "EOF" has been reached.
this is fine as long as nobody sends endless datastreams (without termination characters) (flooding) - which would prevent other users to connect. is there a better way to solve this?
i also tried:

```
if(in.available() > 0)
{
query = new byte[in.available()];
in.read(query);
}
```
but for some reason this does not work with a normal client connection - the connection is ok
but there's no avaiable data.

is it possible to set a timeout for a inputstreamreader - so other clients are able to connect?
maybe somebody got an  idea.
thanx,
mischka[/code]


----------



## Roar (13. Apr 2004)

hmm...

you can set a timout for your socket

```
sock.setTimeOut(300);
```

or you can read from your inputstream for a given time, or read only a given number of chars  ???:L


----------



## Guest (13. Apr 2004)

Socket's setSoTimeout seems to work fine. thanx.


----------

