I am trying to set up a TCP socket stream between two computers on different networks.
client.py (my computer)
import socket
def client_program():
host = "46.117.186.128" #server public ip
port = 45_000 # socket server port number
s = socket.socket()
addr = (host, port)
print("Connected to " + str(addr))
print(s.connect(addr))
message = input(" -> ") # take input
while message.lower().strip() != 'bye':
s.send(message.encode('utf-8'))
print("From Server: ", s.recv(1024))
message = input("-> ")
s.close()
client_program()
server.py (computer on a different network)
import socket
s = socket.socket() # Create a socket object
host = '192.168.0.104' #private ip address of server
port = 45000
s.bind((host, port))
s.listen(5)
c, addr = s.accept()
print 'Got connection from', addr
while True:
c.send(raw_input("Server please type: "))
print "From Client: ", c.recv(1024)
c.close()
The server's network has port forwarding from external port 45000-> internal port 45000
when I try to connect I get TimeoutError: [WinError 10060] The connection could not be established because the connected caller did not respond correctly after a certain period of time. Or the established connection failed because the connected host did not respond.
I've tried a ping between the two networks and it times out too.
running tracert between the two also begins to timeout after 9 or so hops.
both subnet masks are 255.255.255.0 (/24)
I believe the problem lies within the networking and not the code, any help?
question from:
https://stackoverflow.com/questions/65642035/tcp-socket-over-seperate-networks-and-port-forwarding 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…