How to set up a 'listening' Unix domain socket

Robert Latest boblatest at yahoo.com
Mon Mar 22 07:43:51 EDT 2021


Chris Angelico wrote:
>
> Hmm, your formatting's messed up, but the code looks fine to me. (Be aware
> that you seem to have a "selr" where it should be "self".)

Didn't catch that because my program didn't even get to that point ;-)

>
>> However, when I try to send somthing to that socket, I get this error
>> message:
>>
>> $ echo "Hello" | socat - UNIX-SENDTO:/tmp/test.socket 2021/03/22 11:03:22
>> socat[2188] E sendto(5, 0x55a22f414990, 6, 0, AF=1 "/tmp/test.socket", 18):
>> Protocol wrong type for socket
>>
>
> Not familiar with socat, but here's some simple Python code to trigger your
> server:
>
>>>> import socket sock = socket.socket(socket.AF_UNIX)
>>>> sock.connect("/tmp/test.socket") sock.send(b"Hello, world")
> 12
>>>> sock.close()
>>>>

Works perfectly, thanks! I'm probably not using socat right.

robert


More information about the Python-list mailing list