Am 31.12.2016 um 12:04 schrieb Tomaž Kunaver:
> Actually, I'm not getting any exceptions.
You should.
I don't know whether that's the case for your code, but many people do
stuff like
try {
// do something that may throw exceptions
} catch (Exception ex) {
// ignore
}
which silently swallows any exceptions.
Instead, the code should be
try {
// do something that may throw exceptions
} catch (Exception ex) {
// this if the caller shouldn't continue:
throw new RuntimeException(ex);
// if the error should be output instead
// (for some suitable preinitialized logger accessible as 'log':
log.error("some text that explains what operation failed", ex);
}
Servers definitely need logging BTW. One cannot debug servers easily
(clients would run into timeouts etc.), and without a debugger, the best
replacement is a good log.
> What I want to do though is to
> LIMIT my connections to like 100, since my game server does a lot of
> work with each client and I don't want more than 100 clients connecting,
> or else my server would become too slow.
On a Linux server, you can enforce a limit on the number of open file
handles, which includes TCP connections. Since database connections and
open files count in as well, you would need to measure how many files
are actually open and discout for that, plus be ready for surprises, so
it's more like a stopgap solution.
If you want to play safe and limit the number of game clients
connecting, you'd better do that at the caller level, i.e. the piece of
code that keeps track of connected game clients.
Otherwise you might get the same problem as with file handles: Some
library you're using and you aren't even aware that it uses Kryonet
might create Kryonet connection that suddenly start draining your game
client connection limit.