Answer the question
In order to leave comments, you need to log in
Connecting a client to a server outside of the local area, how to do it?
There is a task to make a client-server program in python. Communication between client and server is done using sockets. On the local network it is possible to connect, but not on the global one.
Server code:
import socket
host = socket.gethostbyname(socket.gethostname())
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM,)
server.bind((host, 9090))
server.listen()
while True:
user, addr = server.accept()
user.send("Connected".encode('utf-8'))
pass
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM,)
client.connect((внутренний айпишник хоста, 9090))
while True:
data = client.recv(2048)
print(data.decode('utf-8'))
pass
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question