use of com.rs.entity.player.Client in project runesource by PureCS.
the class Server method accept.
/**
* Accepts any incoming connections.
*
* @throws IOException
*/
private void accept() throws IOException {
SocketChannel socket;
/*
* Here we use a for loop so that we can accept multiple clients per
* tick for lower latency. We limit the amount of clients that we
* accept per tick to better combat potential denial of service type
* attacks.
*/
for (int i = 0; i < 10; i++) {
socket = serverChannel.accept();
if (socket == null) {
// No more connections to accept (as this one was invalid).
break;
}
// Register the connection
HostGateway.enter(socket.socket().getInetAddress().getHostAddress());
// Set up the new connection.
socket.configureBlocking(false);
SelectionKey key = socket.register(selector, SelectionKey.OP_READ);
Client client = new Player(key);
System.out.println("Accepted " + client + ".");
getClientMap().put(key, client);
}
}
Aggregations