Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ENOENT while creating a UNIX socket in Ruby

Tags:

unix

ruby

sockets

I'm trying to create a socket in Ruby using

require "socket"
w = UNIXSocket.new("socket")

and I keep running into

No such file or directory - socket (Errno::ENOENT)

This looks completely backwards to me, because new() is supposed to create that missing file. What am I missing?

like image 857
Vlad the Impala Avatar asked Sep 30 '10 02:09

Vlad the Impala


1 Answers

This is super old. Please don't try to use it verbatim anymore.

http://blog.antarestrader.com/posts/153

#!/ruby
file = 'path/to/my/socket'
File.unlink if File.exists(file) && File.socket?(file)
server = UNIXServer.new(file)
# return a UNIXSocket once a connection is made 
socket = server.accept
# socket is now ready to communicate.

UnixServer makes the socket, UnixSocket only connects to an existing socket.

like image 190
Chuck Vose Avatar answered Oct 17 '22 07:10

Chuck Vose