C
C
cheston2020-11-13 18:32:15
Python
cheston, 2020-11-13 18:32:15

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


Client code:
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

1 answer(s)
B
bbkmzzzz, 2020-11-14
@bbkmzzzz

Run to read about opening / forwarding ports, the differences between gray / white ip address, NAT and vpn, most likely

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question