- 12.4k
- 7
- 29
- 42
This one was getting me for a while too.
ToTo connect to an arbitrary client you must bind the socket to either
socket.gethostname() whichsocket.gethostname() which is what I'm using with success.
or or use empty string ""
In""
In reference to the server code:
A couple things to notice: weWe used socket.gethostname()socket.gethostname() so that the socket would be visible to the outside world. If we had used s.bind(('localhost', 80))
s.bind(('localhost', 80))
or s.bind(('127.0.0.1', 80))
s.bind(('127.0.0.1', 80))
we would still have a "server" socket, but one that was only visible within the same machine. s.bind(('', 80))s.bind(('', 80)) specifies that the socket is reachable by any address the machine happens to have.
This one was getting me for a while too. To connect to an arbitrary client you must bind the socket to either socket.gethostname() which is what I'm using with success. or use empty string "" In reference to the server code: A couple things to notice: we used socket.gethostname() so that the socket would be visible to the outside world. If we had used s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would still have a "server" socket, but one that was only visible within the same machine. s.bind(('', 80)) specifies that the socket is reachable by any address the machine happens to have.
To connect to an arbitrary client you must bind the socket to either
socket.gethostname() which is what I'm using with success or use empty string ""
In reference to the server code: We used socket.gethostname() so that the socket would be visible to the outside world. If we had used
s.bind(('localhost', 80))
or
s.bind(('127.0.0.1', 80))
we would still have a "server" socket, but one that was only visible within the same machine.s.bind(('', 80)) specifies that the socket is reachable by any address the machine happens to have.
This one was getting me for a while too. To connect to an arbitrary client you must bind the socket to either socket.gethostname() which is what I'm using with success. or use empty string "" In reference to the server code: A couple things to notice: we used socket.gethostname() so that the socket would be visible to the outside world. If we had used s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would still have a "server" socket, but one that was only visible within the same machine. s.bind(('', 80)) specifies that the socket is reachable by any address the machine happens to have.