Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

UDPSocket#send

(::String msg, ?::Integer flags, ?::String host, ?::Integer port) -> ::Integer
udpsocket.send(mesg, flags, host, port) => numbytes_sent
udpsocket.send(mesg, flags, sockaddr_to) => numbytes_sent
udpsocket.send(mesg, flags) => numbytes_sent

Sends mesg via udpsocket.

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

Example
u1 = UDPSocket.new
u1.bind("127.0.0.1", 4913)

u2 = UDPSocket.new
u2.send "hi", 0, "127.0.0.1", 4913

mesg, addr = u1.recvfrom(10)
u1.send mesg, 0, addr[3], addr[1]

p u2.recv(100) #=> "hi"
See also #recvfrom_nonblock #connect also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0