J
jamesgoode
Hi,
I'm trying to create a multi-user TCP server, without the use of a
thread-per-connection model. My plan is to create an instance of the
ClientConnection class, which is stored in an array, for each
connection. A 'connection listener' thread handles this. The inputs
from the clients are then handled in a loop, which looks like this:
while (true)
{
for (int i = 0; i < MAX_CONNECTIONS; i++)
{
try {
if (connections!=null)
if (connections.in.ready())
connections.out.writeBytes(connections.in.readLine()+"\n
\r");
} catch (IOException e) {
// TODO Auto-generated catch block
connections = null;
}
}
}
(connections.in is a BufferedReader)
The problem is, that BufferedReader.ready() always seems to return
true, and that BufferedReader.readLine() halts the program until there
is a line to read.
All help is greatly appreciated.
Many thanks,
--James.
I'm trying to create a multi-user TCP server, without the use of a
thread-per-connection model. My plan is to create an instance of the
ClientConnection class, which is stored in an array, for each
connection. A 'connection listener' thread handles this. The inputs
from the clients are then handled in a loop, which looks like this:
while (true)
{
for (int i = 0; i < MAX_CONNECTIONS; i++)
{
try {
if (connections!=null)
if (connections.in.ready())
connections.out.writeBytes(connections.in.readLine()+"\n
\r");
} catch (IOException e) {
// TODO Auto-generated catch block
connections = null;
}
}
}
(connections.in is a BufferedReader)
The problem is, that BufferedReader.ready() always seems to return
true, and that BufferedReader.readLine() halts the program until there
is a line to read.
All help is greatly appreciated.
Many thanks,
--James.