开发者

ENOENT while creating a UNIX socket in Ruby

开发者 https://www.devze.com 2023-01-17 23:33 出处:网络
I\'m trying to create a socket in Ruby using require \"socket\" w = UNIXSocket.new(\"socket\") and I keep running into

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消