为什么python插座不接收数据包?
我的程序没有收到任何数据包(在UDP,Windows 10上),但是当我在Wireshark上嗅探数据时,我可以看到数据确实已发送。我知道这与我的本地网络无关,因为当我切换到热点时,它仍然无法使用。
另一件事是,该程序会为我在同一项目中与我合作的朋友接收数据,但是对于我来说,即使我为客户端和服务器使用了同一台计算机,也无法使用。
绑定套接字后通过os
模块在程序中启用混杂
if os.name == “nt”:
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
什至尝试通过添加这些行
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
我 ?
这就是我设置套接字的方式:
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} [!][!]")
这就是我接收数据包的方式:
while run:
data, ip = s.recvfrom(bufferSize)
data = str(data)
data = data[2:]
data = data[:-1]
if data == "":
continue
print(data)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论