network programming: how does s.accept() work?

Frank Millman frank at chagford.com
Tue Feb 26 13:51:35 CET 2008



7stud wrote:
>
> If two sockets are bound to the same host and port on the server, how
> does data sent by the client get routed?  Can both sockets recv() the
> data?

I have learned a lot of stuff I did not know before from this thread,
so I think I can answer that.

There must be a layer of software that listens at the port. When it
receives a packet, it can tell which client sent the packet (host and
port number). It uses that to look up which socket is handling that
particular connection, and passes it as input to that socket.

Therefore each socket only receives its own input, and is not aware of
anything received for any other connection.

Not a technical explanation, but I think it describes what happens.

Frank Millman



More information about the Python-list mailing list