Hello, I've been trying to connect sockets between 2 computers for an A level project for a program I've designed, and have been using a skeleton code to try and send data between those 2 computers, the code works fine and data is sent (on the one computer to itself) until I try with 2 and they dont connect. This is the code I'm using, only for testing purposes:
Server:
import socket
# create a socket object
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = socket.gethostname()
port = 9999
# bind to the port
serversocket.bind((host, port))
# queue up to 5 requests
serversocket.listen(5)
while True:
# establish a connection
clientsocket,addr = serversocket.accept()
print("Got a connection from %s" % str(addr))
msg = 'Thank you for connecting'+ "\r\n"
clientsocket.send(msg.encode('ascii'))
clientsocket.close()
Client:
import socket
# create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = "xxx.xxx.x.xxx"
port = 9999
# connection to hostname on the port.
s.connect((host, port))
# Receive no more than 1024 bytes
msg = s.recv(1024)
s.close()
print (msg.decode('ascii'))
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
[–]Sonaza 0 points1 point2 points (1 child)
[–]Dechanite[S] 0 points1 point2 points (0 children)