![](/img/trans.png)
[英]urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows
[英]Python socket error on Windows 10045
import socket
# the public network interface
HOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))
# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) //Error Occurs on this line
# receive a package
print(s.recvfrom(65565))
# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
當我嘗試運行此代碼時,我得到:
Traceback (most recent call last):
File "D:/Users/Gen/PycharmProjects/hex2float/socketerror.py", line 14, in <module>
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
OSError: [WinError 10045] The attempted operation is not supported for the type of object referenced
這段代碼取自Python文檔,所以我很困惑為什么它不起作用。 誰能解釋為什么?
也許你需要刪除socket.AF_INET
從u句子s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
因為我使用不帶AF_INET
SOCK_DGRAM
成功構建服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.