jsonsocket icon indicating copy to clipboard operation
jsonsocket copied to clipboard

Only single client

Open joders opened this issue 6 years ago • 1 comments

Do I interpret this correctly that you are effectively allowing only a single client to connect? Even though the maximum amount of connections is set to 5 in the call to listen an established connection is dropped as soon as a new connection request is issued.

joders avatar Jan 25 '18 20:01 joders

This is an old issue, and I think your interpretation is mostly correct there can only really be one active accepted connection at a time. I think you're slightly misinterpreting what listen does though.

5 in the call to listen isn't the maximum number of connections. It's the maximum number of clients that can be queued up waiting for a connection. Theoretically a socket server (not this one) that calls listen with 5 as a parameter could have dozens of accepted client connections; its queue of unaccepted client connections could only be 5 though.

The fact that this implementation of accept calls close on the current connection though is definitely limiting and somewhat single client.

Its very limitedly multi client though in the sense that clients do enter the queue. So theoretically you could have a timeline like: create server create client1 connected to server create client2 connected to server client1 sends j1 client2 sends j2 client1 sends j3

server accept (connects to client1) server recv returns j1 server recv returns j3 server send here would only go to current connection (client1) server accept (connects to client2 closes client1) server recv returns j2 (this waits in the queue too even though it wasn't accepted until after it was sent)

If the server queue was full, the client call to connect would block and time out.

maxullman avatar Apr 19 '18 20:04 maxullman