instance method
BasicSocket#recv
(::Integer maxlen, ?::Integer flags, ?::String outbuf) -> ::String
(::Integer maxlen, ?::String outbuf) -> ::String
basicsocket.recv(maxlen[, flags[, outbuf]]) => mesg
ext/socket/basicsocket.c
View on GitHub ↗
static VALUE
bsock_recv(int argc, VALUE *argv, VALUE sock)
{
return rsock_s_recvfrom(sock, argc, argv, RECV_RECV);
}
Receives a message.
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
UNIXSocket.pair {|s1, s2| s1.puts "Hello World" p s2.recv(4) #=> "Hell" p s2.recv(4, Socket::MSG_PEEK) #=> "o Wo" p s2.recv(4) #=> "o Wo" p s2.recv(10) #=> "rld\n" }
See also
#local_address
#recvmsg
#getsockopt
#recvmsg_nonblock
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0