Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 10045上的Python套接字错误_Python - Fatal编程技术网

Windows 10045上的Python套接字错误

Windows 10045上的Python套接字错误,python,Python,当我尝试运行此代码时,我得到: 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((H

当我尝试运行此代码时,我得到:

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)
回溯(最近一次呼叫最后一次):
文件“D:/Users/Gen/PycharmProjects/hex2float/socketerror.py”,第14行,在
s、 ioctl(socket.SIO_RCVALL,socket.RCVALL_ON)
OSError:[WinError 10045]引用的对象类型不支持尝试的操作

这段代码取自Python文档,所以我不明白为什么它不起作用。有人能解释一下原因吗?

也许您需要从u语句中删除
socket.AF\u INET
s=socket.socket(socket.AF\u INET,socket.SOCK\u RAW,socket.IPPROTO\u IP)

当我使用
SOCK_DGRAM
而不使用
AF_INET
成功构建服务器时

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