Skip to content
instance method

UNIXSocket#recvfrom

(::Integer maxlen, ?::Integer flags, ?::String outbuf) -> [ ::String, [ ::String, ::String ] ]
unixsocket.recvfrom(maxlen [, flags[, outbuf]]) => [mesg, unixaddress]

Receives a message via unixsocket.

maxlen is the maximum number of bytes to receive.

flags should be a bitwise OR of Socket::MSG_* constants.

outbuf will contain only the received data after the method call even if it is not empty at the beginning.

Example
s1 = Socket.new(:UNIX, :DGRAM, 0)
s1_ai = Addrinfo.unix("/tmp/sock1")
s1.bind(s1_ai)

s2 = Socket.new(:UNIX, :DGRAM, 0)
s2_ai = Addrinfo.unix("/tmp/sock2")
s2.bind(s2_ai)
s3 = UNIXSocket.for_fd(s2.fileno)

s1.send "a", 0, s2_ai
p s3.recvfrom(10) #=> ["a", ["AF_UNIX", "/tmp/sock1"]]
See also #peeraddr #recv_io #path #send_io also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0