I started learning Socket in Python. Moreover, when connecting to the server (which was running on my computer), everything worked, but when my friend tried to connect to me from another PC, the client simply could not detect the server and connect to it.
I wrote client and server:
#client
import socket
host = ""
port = 1234
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.settimeout(10)
client.connect((host, port))
client.settimeout(None)
print("connected")
client.send(("Hellow world!").encode())
#server
import socket
host = ""
port = 1234
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host, port))
server.listen(10)
print("server launched")
while True:
conn, addr = server.accept()
print("Connect from", addr)
data = conn.recv(1024)
data = data.decode()
print(data)
A friend tried to start the client, but for some reason, the client can’t connect to the server.
New contributor
Snair One is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.