I want to connect my two different devices using sockets library in Python. Both my devices are connected to the same Internet connection. I tried to use the sockets library to establish the connection. I ran the server script on one device and the client script on another device and tried to establish a connection. But the connection was not established. Is there a problem in my code or there is some other issue?
server.py:-
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((socket.gethostbyname(socket.gethostname()), 5050))
print("Server Starting")
sock.listen()
while True:
conn, addr = sock.accept()
print("New connection " + str(addr))
client.py:-
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('Server IP address', 5050))
socket.gethostname()return? It should be the IP you are trying you connect to, or '0.0.0.0' (which it won't be, but you could put it manually there).