I'm trying to modify the EchoServer example in a way, that only one client is allowed to connect to the server. If the server has a single connection, no other connect should be possible, it must be denied.
Any help in how to accomplish this?

> I'm trying to modify the EchoServer example in a way, that only one client is allowed to connect to the server. If the server has a single connection, no other connect should be possible, it must be denied.
> Any help in how to accomplish this?

As things currently stand, you can not do that from the sample code side. The way to it would be to extend ))SocketReactor(( interface with a member function that would give you the number of handlers.
Then, you would query the reactor in ))EchoServiceHandler(( and act appropriately depending on whether there are any active event handlers or not.

There may be specifics to your application that I am not aware of, but using reactor to achieve such functionality seems awkward. A logical approach would be to use TCPServer in conjunction with TCPServerParams::setMaxQueued().

I would also say that unless you're a big fan on the Reactor pattern, then using the SocketReactor for a server that serves only a single connection is a bit, um, inappropriate. For this case, even using a plain ServerSocket and calling acceptConnection() in a loop would probably do it.

If you absolutely must use the reactor, an option would be to create your own implementation of the SocketAcceptor. Alternatively, have the ServiceHandler's constructor unregister the SocketAcceptor and its destructor register the SocketAcceptor again. But that seems a bit hacky...

The thing I want to achieve is: The server must not accept a new connection as long as it serves the one and only connection from a connected client. It must not matter, from where the client connection originates. The server must refuse any new connection, if one client is connected.

As written, I took the timeserver having the TCPServerParams set and the run() method of TimeServerConnection is looping and printing timestamps. From localhost I start telnet, connect to the server and get the timestamps printed in the telnet console, then I let it run and connect to server using another telnet session. And again I let me connect and also will printout timestamps. The same happens with a third telnet client connection. So in total I have three client and all get data from the server. But what I want is, that I can only establish the one and only connection. If this one and only connection gets closed, a new client connection should succeed.

> If this one and only connection gets closed, a new client connection should succeed.

Then my original advice clearly will not satisfy your requirements . You can leave the default number of queued connections as is and put the logic of whether to reply or not in in your ))TimeServerConnection(( with ))TimeServerConnectionFactory(( memorizing the currently connected client.

However, all that seems bit too high-level for your case. If you would like to refuse the connection earlier, then I have to agree with Guenter's advice - use ))ServerSocket(( and do your own logic. Look at Net/testsuite/src/EchoServer.cpp for example. If you will have custom code on the client side, then ))DialogSocket(( may come handy as well (see Net/testsuite/src/DialogSocketTest).