1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>gen_udp</title>
27
<prepared>tony@erix.ericsson.se</prepared>
29
<date>1997-12-03</date>
32
<module>gen_udp</module>
33
<modulesummary>Interface to UDP sockets</modulesummary>
35
<p>The <c>gen_udp</c> module provides functions for communicating
36
with sockets using the UDP protocol.</p>
40
<title>DATA TYPES</title>
49
as returned by open/1,2</code>
53
<name>open(Port) -> {ok, Socket} | {error, Reason}</name>
54
<name>open(Port, Options) -> {ok, Socket} | {error, Reason}</name>
55
<fsummary>Associate a UDP port number with the process calling it</fsummary>
57
<v>Port = 0..65535</v>
58
<v>Options = [Opt]</v>
59
<v> Opt -- see below</v>
60
<v>Socket = socket()</v>
61
<v>Reason = posix()</v>
64
<p>Associates a UDP port number (<c>Port</c>) with the calling
66
<p>The available options are:</p>
68
<tag><c>list</c></tag>
70
<p>Received <c>Packet</c> is delivered as a list.</p>
72
<tag><c>binary</c></tag>
74
<p>Received <c>Packet</c> is delivered as a binary.</p>
76
<tag><c>{ip, ip_address()}</c></tag>
78
<p>If the host has several network interfaces, this option
79
specifies which one to use.</p>
81
<tag><c>{fd, int()}</c></tag>
83
<p>If a socket has somehow been opened without using
84
<c>gen_udp</c>, use this option to pass the file
85
descriptor for it.</p>
87
<tag><c>inet6</c></tag>
89
<p>Set up the socket for IPv6.</p>
91
<tag><c>inet</c></tag>
93
<p>Set up the socket for IPv4.</p>
98
<seealso marker="inet#setopts/2">inet:setopts/2</seealso>.</p>
101
<p>The returned socket <c>Socket</c> is used to send packets
102
from this port with <c>send/4</c>. When UDP packets arrive at
103
the opened port, they are delivered as messages:</p>
105
{udp, Socket, IP, InPortNo, Packet}</code>
106
<p>Note that arriving UDP packets that are longer than
107
the receive buffer option specifies, might be truncated
109
<p><c>IP</c> and <c>InPortNo</c> define the address from which
110
<c>Packet</c> came. <c>Packet</c> is a list of bytes if
111
the option <c>list</c> was specified. <c>Packet</c> is a
112
binary if the option <c>binary</c> was specified.</p>
113
<p>Default value for the receive buffer option is
114
<c>{recbuf, 8192}</c>.</p>
115
<p>If <c>Port == 0</c>, the underlying OS assigns a free UDP
116
port, use <c>inet:port/1</c> to retrieve it.</p>
120
<name>send(Socket, Address, Port, Packet) -> ok | {error, Reason}</name>
121
<fsummary>Send a packet</fsummary>
123
<v>Socket = socket()</v>
124
<v>Address = string() | atom() | ip_address()</v>
125
<v>Port = 0..65535</v>
126
<v>Packet = [char()] | binary()</v>
127
<v>Reason = not_owner | posix()</v>
130
<p>Sends a packet to the specified address and port.
131
The <c>Address</c> argument can be either a hostname, or an
136
<name>recv(Socket, Length) -> {ok, {Address, Port, Packet}} | {error, Reason}</name>
137
<name>recv(Socket, Length, Timeout) -> {ok, {Address, Port, Packet}} | {error, Reason}</name>
138
<fsummary>Receive a packet from a passive socket</fsummary>
140
<v>Socket = socket()</v>
141
<v>Length = int()</v>
142
<v>Address = ip_address()</v>
143
<v>Port = 0..65535</v>
144
<v>Packet = [char()] | binary()</v>
145
<v>Timeout = int() | infinity</v>
146
<v>Reason = not_owner | posix()</v>
149
<p>This function receives a packet from a socket in passive
151
<p>The optional <c>Timeout</c> parameter specifies a timeout in
152
milliseconds. The default value is <c>infinity</c>.</p>
156
<name>controlling_process(Socket, Pid) -> ok</name>
157
<fsummary>Change controlling process of a socket</fsummary>
159
<v>Socket = socket()</v>
163
<p>Assigns a new controlling process <c>Pid</c> to
164
<c>Socket</c>. The controlling process is the process which
165
receives messages from the socket.</p>
169
<name>close(Socket) -> ok | {error, Reason}</name>
170
<fsummary>Close a UDP socket</fsummary>
172
<v>Socket = socket()</v>
173
<v>Reason = not_owner | posix()</v>
176
<p>Closes a UDP socket.</p>