views:

42

answers:

1

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?

+2  A: 

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.

Chuck Vose
Wow, thank you. It's crazy that this information isn't more easily accessible. Every example I found showed new as creating a new socket.
Goose Bumper