Communication between two computers using python socket

后端 未结 5 1228
不知归路
不知归路 2020-12-13 11:33

I am using these two programs to communicate between two of my computers, one that I am ssh\'d into and I am not returning anything on either side. It just runs without send

5条回答
  •  春和景丽
    2020-12-13 11:52

    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.

    source

提交回复
热议问题