Answer the question
In order to leave comments, you need to log in
Why doesn't UDP hole punching work?
Good afternoon, there is an attempt at my own implementation of UDP-hp, but not working, I will be grateful for any answer.
Code:
Server:
import socket
from pickle import dumps
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("192.168.0.122", 4545))
msg, addr1 = sock.recvfrom(1024)
msg, addr2 = sock.recvfrom(1024)
sock.sendto(dumps(addr2), addr1)
sock.sendto(dumps(addr1), addr2)
import socket
from pickle import loads
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("192.168.0.122", 50000(и 50001 для второго клиента)))
server = ("Белый ip адрес сервера", 4545)
sock.sendto("Hi".encode(), server)
msg, addr = sock.recvfrom(1024)
another = loads(msg)
sock.settimeout(0.1)
while True:
try:
sock.sendto("Hello".encode(), another)
cl, ms = sock.recvfrom(1024)
print(cl.decode())
except socket.timeout:
continue
Answer the question
In order to leave comments, you need to log in
All three work for you on one machine? It is not very clear - what effect are you trying to achieve then and in which place exactly to break through. draw yourself packet paths, especially through the firewall rules on the router.
Well, yes, not every nut breaks through in such a naive way. If we talk about providers, then rather - almost none
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question