ENOENT while creating a UNIX socket in Ruby
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 (Er开发者_运维百科rno::ENOENT)
This looks completely backwards to me, because new()
is supposed to create that missing file. What am I missing?
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.
精彩评论