gpt4 book ai didi

python 错误: 'module' object has no attribute 'AF_UNIX'

转载 作者:太空狗 更新时间:2023-10-30 02:35:02 24 4
gpt4 key购买 nike

这是我的 python 代码:

if __name__ == '__main__':  
import socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(('0.0.0.0', 4000))
import time
time.sleep(2)
#sock.send('1')
print sock.recv(1024)
sock.close()

它显示:

Traceback (most recent call last):
File "D:\Program Files\test\test\python\client.py", line 3, in <module>
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'AF_UNIX'

我能做什么,

谢谢

更新:

Traceback (most recent call last):
File "D:\Program Files\test\test\python\client.py", line 4, in <module>
sock.connect(('0.0.0.0', 4000))
File "<string>", line 1, in connect
socket.error: (10049, "Can't assign requested address")

最佳答案

在 Windows 上创建套接字对象时,您应该这样做:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

AF_INET 用于 Internet 地址,AF_UNIX 用于 UNIX 进程间通信。后者显然只能在 UNIX 平台上使用。

另外,关注this example了解如何实现简单的套接字服务器和客户端。

关于 python 错误: 'module' object has no attribute 'AF_UNIX' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5088087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com