2

I'm trying to get Python socket working as an alternative to calling the command line socat.

This socat command works fine:

echo 'cmd' | sudo socat stdio <path-to-socket>

but when I run this python code, I get an error:

>>> import socket
>>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> s.connect(<path-to-socket>)
>>> s.send('cmd')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.error: (32, 'Broken pipe')

Any ideas what the issue is? Thanks.

1
  • Which version of python you are using . I am trying to create a unix socket client program using python 2.7 /3.3 . but it says AF_UNIX was not supported . Can you help me ? Commented Jul 10, 2013 at 6:16

2 Answers 2

4

There's one obvious difference between your echo | socat line and your Python code, and that's the newline that echo adds but you don't send in your Python code. I don't see how that could cause the broken pipe error. Your basic approach seems fine, and it works fine when I test locally. Are you sure the server process isn't doing something extra here? Are you sure it's still listening, and hasn't, for example, closed the other end of the socket for some reason?

Sign up to request clarification or add additional context in comments.

Comments

1

I was having this problem, and it ended up being that my code worked fine when in a script - but got a broken pipe when working interactively. I guess there's a timeout or something.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.