Python Forum

Full Version: client A to server B connects but client B to server A doesnt connect
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

Computer A is connected by cable and computer B is connected by WIFI. When I run a server on computer A I can receive a string message sent from computer B.

However, when I host a server on computer B, running the same scripts, I can't receive a string message from computer A. The ip number shown in the examples is that of my WIFI server which doesn't receive a message.

Both computers run Linux Ubuntu -> xfce

client: (computer A connected by inet cable)
    
def Client(self): 
        server_ip,server_port = "10.0.0.16",7000 
        client_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
        while True:
            message="message received"
            client_socket.sendto(message.encode(),(server_ip,server_port))
            break
        client_socket.close()
server: (Computer B connected by WIFI)
import socket

if __name__ == '__main__':  
    BinanceBuy = ""
    server_ip="10.0.0.16"
    server_port=7000

    server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server_socket.bind((server_ip,server_port))

    while True:
        data,client_adress = server_socket.recvfrom(1024)
        message=data.decode().strip()
        print(f'received word = {message}') # no message is shown when I run this server script on my WIFI computer
It doesn't give me an error, it's just that it doesn't display the string message sent from computer A.
Any help would be much appreciated !
Try the example in the Python documentation where the server performs the sequence socket() bind() listen() accept() and the client performs the sequence socket() connect().