'Why doesn't the Python socket receive packets?
My program doesn't receive any packets (on UDP, Windows 10), but when I sniff the data on Wireshark I can see that the data is indeed sent. I know that it doesn't have anything to do with my local network because when I switch to a hotspot it still doesn't work.
Another thing is that the program receives the data for my friends who work with me on the same project, but for me, even if I'm using the same computer for the client and server it doesn't work.
I even tried to enable Promiscuous in the program via the os
module after binding the socket by adding these lines:
if os.name == “nt”:
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
but all I got was
Traceback (most recent call last):
File "C:/Users/roeym/PycharmProjects/client game/tank_trouble_dynamic_map.py", line 5, in <module>
import tank_client
File "C:\Users\roeym\PycharmProjects\client game\tank_client.py", line 13, in <module>
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
OSError: [WinError 10022] An invalid argument was supplied
Can you please help me figure out why my program doesn't receive the data?
This is how I set the socket up:
ip = socket.gethostbyname(socket.gethostname())
port = 8888
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
s.bind((ip, port))
print(f"[!][!] Server is up, running on {ip}, port- {port} [!][!]")
and this is how I receive packets:
while run:
data, ip = s.recvfrom(bufferSize)
data = str(data)
data = data[2:]
data = data[:-1]
if data == "":
continue
print(data)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|