S
S
Slavik09812018-07-28 14:42:54
Python
Slavik0981, 2018-07-28 14:42:54

Problem with SOCKETS in Python not over LAN?

Need help. Created a client-server chat It works on the local network, but NO via the Internet. And I looked at the external IP on 2ip.ru after entering the IP in the server part of the program, the error OSError: [WinError 10049] The required address for its context is incorrect. What to do?
IP is static.
Server code:

# -*- coding: utf-8 -*- 
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind(('ВНЕШНИЙ АЙПИ',9090))
while 1:
  message = s.recv(128)
  print (message)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xmoonlight, 2018-07-28
@xmoonlight

1. Specify the real external IP in the binding code, run it and check whether the port is open here or not: https://portchecker.co/
2. If the router - then specify (change!) In the binding code the INTERNAL IP of the computer and do port forwarding/mirroring from the external network to the inside.
There is no need to forward the port only when the IP of the computer matches the external IP check on any web checker, for example, on myip.ru. This means that your computer is connected directly to the Internet without additional intermediate networks (usually through a router).

R
res2001, 2018-07-28
@res2001

External IP, most likely on the router, and on the router - NAT. You need to configure port forwarding on a computer inside the local network.
It is possible that the provider has an external IP in general, and you need a wire. gives a private address. In this case, you need to buy a white address from the operator for money.

V
V. CHORNYI, 2020-03-15
@Vchornyi

Hello, I'm new to this business.
Trying to open Client/Server Chat as described in https://www.youtube.com/watch?v=MPjgHxK8k68&t=59s
I have Windows 10, I run two attached files via Windows Console (cmd.exe):

  • python "D:\PATH_TO_FILE\server.py"
  • python "D:\PATH_TO_FILE\client.py"

If you leave the line server = ("192.168.0.101",9090) in the "client.py" file , then nothing happens, that is, the server "does not receive" messages. If you change server = ("",9090)
to an empty server , then it gives the same error as in the header - OSError: [WinError 10049] The required address for its context is incorrect. It is difficult to understand where to dig further, how to determine the IP address (Socket?) of the server, or in general, how to "unblock" the port in Windows.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question