Name

UDPSocket — UDP socket class

Synopsis

UDPSocket is a class for User Datagram Protocol (UDP), which is a connectionless, unreliable protocol.

Required Library

require ’socket’

Inherited Class

IPSocket

Class Methods

UDPSocket::new([socktype=Socket::AF_INET])
UDPSocket::open([socktype=Socket::AF_INET])

Creates a UDP datagram socket

Instance Methods

s.bind(host, port)

Binds the socket to port on host. host may be an empty string (“”) for INADDR_ANY or <broadcast> for INADDR_BROADCAST.

s.connect(host, port)

Connects the socket to port on host. host may be an empty string (“”) for INADDR_ANY or <broadcast> for INADDR_BROADCAST.

s.send(mesg, flags[, to])
s.send(mesg, flags[, host, port])

Sends data on a socket s, returning the length of the data sent. If only two arguments are specified, the destination is assumed to be the port of the existing connection. Otherwise, it may be specified using a struct sockaddr when calling the method with three arguments or by indicating host and port when specifying four arguments.

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.