I'm trying to make a chat server thing. Basically, I want more than one client to be able to connect at the same time.
I want it so it's always listening. Whenever anyone tries to connect, it instantly accepts them and adds them to a list of connections.
I could have a listen(1) then a timeout, and keep appending them to a list then closing the socket, and making a new one, then listening with a timeout, etc. Although, this seems very slow, and I'm not even sure it would work
Keep in mind, it does not HAVE to be socket. If there is any other kind of network interface, it would work just as well.
Consider whether you actually need to maintain separate sockets for every connection.  Would something like connectionless UDP be appropriate?  That way you could support an arbitrary number of users while only using one OS socket.
Of course, with this approach you'd need to maintain connection semantics internally (if your application cares about such things);  figure out which user each datagram has been sent either by looking at their IP/port or by examining some envelope data within your network protocol, send occasional pings to see whether the other side is still alive, etc.  But this approach should nicely separate you from any OS concerns RE: number of sockets your process is allowed to keep open at once.
Having an infinite amount of sockets connected?