Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

UNIXSocket#recv_io

unixsocket.recv_io([klass [, mode]]) => io

Example

Example
UNIXServer.open("/tmp/sock") {|serv|
  UNIXSocket.open("/tmp/sock") {|c|
    s = serv.accept

    c.send_io STDOUT
    stdout = s.recv_io

    p STDOUT.fileno #=> 1
    p stdout.fileno #=> 7

    stdout.puts "hello" # outputs "hello\n" to standard output.
  }
}

klass will determine the class of io returned (using the IO.for_fd singleton method or similar). If klass is nil, an integer file descriptor is returned.

mode is the same as the argument passed to IO.for_fd

See also #recvfrom #send_io #peeraddr also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0