19972011 Ericsson AB. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. gen_udp tony@erix.ericsson.se 1997-12-03 A
gen_udp Interface to UDP sockets

The gen_udp module provides functions for communicating with sockets using the UDP protocol.

Represents an address of a TCP socket. It is a tuple as explained in inet(3).

See inet(3); POSIX Error Codes.

socket()

As returned by open/1,2.

Associate a UDP port number with the process calling it

Associates a UDP port number (Port) with the calling process.

The available options are:

list

Received Packet is delivered as a list.

binary

Received Packet is delivered as a binary.

{ip, ip_address()}

If the host has several network interfaces, this option specifies which one to use.

{fd, int()}

If a socket has somehow been opened without using gen_udp, use this option to pass the file descriptor for it.

inet6

Set up the socket for IPv6.

inet

Set up the socket for IPv4.

Opt

See inet:setopts/2.

The returned socket Socket is used to send packets from this port with send/4. When UDP packets arrive at the opened port, they are delivered as messages:

{udp, Socket, IP, InPortNo, Packet}

Note that arriving UDP packets that are longer than the receive buffer option specifies, might be truncated without warning.

IP and InPortNo define the address from which Packet came. Packet is a list of bytes if the option list was specified. Packet is a binary if the option binary was specified.

Default value for the receive buffer option is {recbuf, 8192}.

If Port == 0, the underlying OS assigns a free UDP port, use inet:port/1 to retrieve it.

Send a packet

Sends a packet to the specified address and port. The Address argument can be either a hostname, or an IP address.

Receive a packet from a passive socket

This function receives a packet from a socket in passive mode.

The optional Timeout parameter specifies a timeout in milliseconds. The default value is infinity.

Change controlling process of a socket

Assigns a new controlling process Pid to Socket. The controlling process is the process which receives messages from the socket.

Close a UDP socket

Closes a UDP socket.