Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only single client #7

Open
joders opened this issue Jan 25, 2018 · 1 comment
Open

Only single client #7

joders opened this issue Jan 25, 2018 · 1 comment

Comments

@joders
Copy link

joders commented Jan 25, 2018

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.

@maxullman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants