ofxNetwork NumClients() count worries me


I’m a C++ noob, but am slowly picking it up. I’ve looked through some of the source for the TCPServer implemetation of ofxNetwork and something worries me.

There is an upper limit for number of clients “#define TCP_MAX_CLIENTS 32” in the server header; but in the implementation, it is tied to the “int count” which never seems to decrement, only increase as clients connect.

From what I’ve seen, most examples are for a client to connect, stay connected, and incoming things to be streamed via the TCP socket. I need something a little different, mainly that TCP packets can come from many clients and connect only to send a little string and then disconnect. But even if they disconnect, the count stays the same. That seems to imply the limit is not about the number of simultaneous connections, but any connections?

I was just wondering if this was intended behaviour. If not, I can try my hand at fixing it to reduce the count whenever a connection is closed.


mmh, nope, that seems a bug, also if a client disconnects the server is going to try to send to it in the sendToAll and similar methods, there should be something like a map of clients instead of an array so when disconnecting a client it’s id disappears. that way it won’t even be necesary to use a count var.

i’ve opened an issue to fix it for next release:


Yay! Thank you Arturo.

I tried making my own version of it using a vector of connections to try and manage them better…but it didn’t work out at all.

But I did sort of find a solution for what I’m trying to do, since I wanted HTTP-like (or ideally HTTP itself) as the communication protocol for sending events to my app, I’m integrating it with this: http://code.google.com/p/mongoose/

It is absolutely awesome and pretty much exactly what I was looking for; just in case anyone needs HTTP-server functionality for their apps.

yes, i know mongoose, haven’t used it very much but it looks great. also i did an ofxHttpServer some time ago using a similar library, libmicrohttpd:


Oh wow! I was looking for exactly such a thing for a while. I guess not hard enough though, because I never found it, but looks great, I’ll give it a shot, thank you very much Arturo.


I had some problems with number of clients connected getting deleted when using sendToAll.

I posted some questions and code at:


I think my solution is only temporary fix (and re-introduces the old problem of counts going up forever)…I’m wondering if this is fixed with further commits from obviousjim etc?

Or if I should do some further hunting?