Communication between two computers using python socket

后端 未结 5 1232
不知归路
不知归路 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 12:02

    The problem is in the address of your client:

    SERVER_IP   = '127.0.0.1'
    

    You are connecting to the local machine and sending data, while your server is sitting on a different ip. You need to connect to either the servers ip or hostname.

    You can verify this by making the client connect first (and fail if it cant)

    ...
    
    import time
    
    mySocket = socket( AF_INET, SOCK_DGRAM )
    mySocket.connect((SERVER_IP,PORT_NUMBER))
    
    while True:
            mySocket.send('cool')
            time.sleep(.5)
    

    Update from comments

    Because you are on a wifi connection, that implies that both these machine are on the local network. You need to find the LAN ip address of the server, to specify it as the target.

    Command-line approach to finding your IP

    • OSX/Linux: ifconfig
    • Windows: ipconfig /all

提交回复
热议问题