From: mfuhr@... (Michael Fuhr) Date: 2004-12-27T08:52:01+09:00 Subject: Re: writing to unix socket Roeland Moors writes: > require 'socket' > sock = Socket.new(Socket::PF_UNIX, Socket::SOCK_STREAM, 0) > sock.connect(Socket::sockaddr_un(device)) > sock.puts('VERSION') > sock.close > > This works sometimes, but sometimes it don't and then I get this > error: > test.rb:4:in `write': Broken pipe (Errno::EPIPE) > from test.rb:4:in `puts' > from test.rb:4 A write fails with EPIPE if the peer has already closed its side of the connection. > I can get it to work always if i put 'sleep 0.1' after > connecting. But way do I have to do this. Is there a better > method? Using sleep to synchronize activities should be a warning that something is wrong; if it works then it's more likely by accident than by design. What's on the other end of the connection? If the peer closes its side before you call puts() then you'll get EPIPE. It's odd that sleeping for 0.1 seconds apparently fixes the problem; I'd have to think about it to see if I could contrive a situation where that would happen. What OS are you using? Have you run a process trace on the peer to see what it does after it accepts your connection? -- Michael Fuhr http://www.fuhr.org/~mfuhr/