Python error: object 'module' does not have attribute 'AF_UNIX'

this is my python code:

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()  

shows:

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'

What can I do,

thank

update:

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")
+3
source share
1 answer

When creating a socket object in Windows, you should:

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

AF_INETfor Internet addresses and AF_UNIXfor UNIX interprocess communication. The latter is obviously only available on UNIX platforms.

Also, follow this example to learn how to implement a simple socket server and client.

+5
source

Source: https://habr.com/ru/post/1794060/


All Articles