<s>
Berkeley	B-Protocol
sockets	I-Protocol
is	O
an	O
application	B-Application
programming	I-Application
interface	I-Application
(	O
API	B-Application
)	O
for	O
Internet	B-Protocol
sockets	I-Protocol
and	O
Unix	B-Protocol
domain	I-Protocol
sockets	I-Protocol
,	O
used	O
for	O
inter-process	B-Operating_System
communication	I-Operating_System
(	O
IPC	O
)	O
.	O
</s>
<s>
It	O
is	O
commonly	O
implemented	O
as	O
a	O
library	B-Library
of	O
linkable	O
modules	O
.	O
</s>
<s>
It	O
originated	O
with	O
the	O
4.2BSD	O
Unix	B-Application
operating	I-Application
system	I-Application
,	O
which	O
was	O
released	O
in	O
1983	O
.	O
</s>
<s>
A	O
socket	B-Protocol
is	O
an	O
abstract	O
representation	O
(	O
handle	O
)	O
for	O
the	O
local	O
endpoint	O
of	O
a	O
network	O
communication	O
path	O
.	O
</s>
<s>
The	O
Berkeley	B-Protocol
sockets	I-Protocol
API	B-Application
represents	O
it	O
as	O
a	O
file	B-Application
descriptor	I-Application
(	O
file	B-Application
handle	I-Application
)	O
in	O
the	B-Operating_System
Unix	I-Operating_System
philosophy	I-Operating_System
that	O
provides	O
a	O
common	O
interface	O
for	O
input	O
and	O
output	O
to	O
streams	B-Operating_System
of	O
data	O
.	O
</s>
<s>
Berkeley	B-Protocol
sockets	I-Protocol
evolved	O
with	O
little	O
modification	O
from	O
a	O
de	O
facto	O
standard	O
into	O
a	O
component	O
of	O
the	O
POSIX	O
specification	O
.	O
</s>
<s>
The	O
term	O
POSIX	B-Protocol
sockets	I-Protocol
is	O
essentially	O
synonymous	O
with	O
Berkeley	B-Protocol
sockets	I-Protocol
,	O
but	O
they	O
are	O
also	O
known	O
as	O
BSD	B-Protocol
sockets	I-Protocol
,	O
acknowledging	O
the	O
first	O
implementation	O
in	O
the	O
Berkeley	B-Operating_System
Software	I-Operating_System
Distribution	I-Operating_System
.	O
</s>
<s>
Berkeley	B-Protocol
sockets	I-Protocol
originated	O
with	O
the	O
4.2BSD	O
Unix	B-Application
operating	I-Application
system	I-Application
,	O
released	O
in	O
1983	O
,	O
as	O
a	O
programming	B-Application
interface	I-Application
.	O
</s>
<s>
Not	O
until	O
1989	O
,	O
however	O
,	O
could	O
the	O
University	O
of	O
California	O
,	O
Berkeley	O
release	O
versions	O
of	O
the	O
operating	B-General_Concept
system	I-General_Concept
and	O
networking	O
library	B-Library
free	O
from	O
the	O
licensing	O
constraints	O
of	O
AT&T	O
Corporation	O
's	O
proprietary	O
Unix	B-Application
.	O
</s>
<s>
All	O
modern	O
operating	B-General_Concept
systems	I-General_Concept
implement	O
a	O
version	O
of	O
the	O
Berkeley	B-Protocol
socket	I-Protocol
interface	I-Protocol
.	O
</s>
<s>
Even	O
the	O
Winsock	B-Application
implementation	O
for	O
MS	O
Windows	O
,	O
created	O
by	O
unaffiliated	O
developers	O
,	O
closely	O
follows	O
the	O
standard	O
.	O
</s>
<s>
The	O
BSD	B-Protocol
sockets	I-Protocol
API	I-Protocol
is	O
written	O
in	O
the	O
C	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
Most	O
other	O
programming	O
languages	O
provide	O
similar	O
interfaces	O
,	O
typically	O
written	O
as	O
a	O
wrapper	B-Library
library	I-Library
based	O
on	O
the	O
C	B-Language
API	B-Application
.	O
</s>
<s>
As	O
the	O
Berkeley	B-Protocol
socket	I-Protocol
API	I-Protocol
evolved	O
and	O
ultimately	O
yielded	O
the	O
POSIX	B-Protocol
socket	I-Protocol
API	B-Application
,	O
certain	O
functions	O
were	O
deprecated	O
or	O
removed	O
and	O
replaced	O
by	O
others	O
.	O
</s>
<s>
The	O
POSIX	O
API	B-Application
is	O
also	O
designed	O
to	O
be	O
reentrant	B-Operating_System
and	O
supports	O
IPv6	B-Protocol
.	O
</s>
<s>
The	O
STREAMS-based	O
Transport	B-Application
Layer	I-Application
Interface	I-Application
(	O
TLI	O
)	O
API	B-Application
offers	O
an	O
alternative	O
to	O
the	O
socket	B-Protocol
API	I-Protocol
.	O
</s>
<s>
Many	O
systems	O
that	O
provide	O
the	O
TLI	O
API	B-Application
also	O
provide	O
the	O
Berkeley	B-Protocol
socket	I-Protocol
API	I-Protocol
.	O
</s>
<s>
Non-Unix	O
systems	O
often	O
expose	O
the	O
Berkeley	B-Protocol
socket	I-Protocol
API	I-Protocol
with	O
a	O
translation	O
layer	O
to	O
a	O
native	O
networking	O
API	B-Application
.	O
</s>
<s>
Plan	B-Operating_System
9	I-Operating_System
and	O
Genode	B-Language
use	O
file-system	O
APIs	B-Application
with	O
control	O
files	O
rather	O
than	O
file-descriptors	O
.	O
</s>
<s>
The	O
Berkeley	B-Protocol
socket	I-Protocol
interface	I-Protocol
is	O
defined	O
in	O
several	O
header	O
files	O
.	O
</s>
<s>
File	O
Descriptionsys/socket.h	O
Core	O
socket	B-Protocol
functions	O
and	O
data	O
structures.netinet/in.h	O
AF_INET	O
and	O
AF_INET6	O
address	O
families	O
and	O
their	O
corresponding	O
protocol	O
families	O
,	O
PF_INET	O
and	O
PF_INET6	O
.	O
</s>
<s>
The	O
Berkeley	B-Protocol
socket	I-Protocol
API	I-Protocol
typically	O
provides	O
the	O
following	O
functions	O
:	O
</s>
<s>
socket( )	O
creates	O
a	O
new	O
socket	B-Protocol
of	O
a	O
certain	O
type	O
,	O
identified	O
by	O
an	O
integer	O
number	O
,	O
and	O
allocates	O
system	O
resources	O
to	O
it	O
.	O
</s>
<s>
bind( )	O
is	O
typically	O
used	O
on	O
the	O
server	O
side	O
,	O
and	O
associates	O
a	O
socket	B-Protocol
with	O
a	O
socket	B-Protocol
address	O
structure	O
,	O
i.e.	O
</s>
<s>
listen( )	O
is	O
used	O
on	O
the	O
server	O
side	O
,	O
and	O
causes	O
a	O
bound	O
TCP	B-Protocol
socket	I-Protocol
to	O
enter	O
listening	O
state	O
.	O
</s>
<s>
connect( )	O
is	O
used	O
on	O
the	O
client	O
side	O
,	O
and	O
assigns	O
a	O
free	O
local	O
port	O
number	O
to	O
a	O
socket	B-Protocol
.	O
</s>
<s>
In	O
case	O
of	O
a	O
TCP	B-Protocol
socket	I-Protocol
,	O
it	O
causes	O
an	O
attempt	O
to	O
establish	O
a	O
new	O
TCP	O
connection	O
.	O
</s>
<s>
It	O
accepts	O
a	O
received	O
incoming	O
attempt	O
to	O
create	O
a	O
new	O
TCP	O
connection	O
from	O
the	O
remote	O
client	O
,	O
and	O
creates	O
a	O
new	O
socket	B-Protocol
associated	O
with	O
the	O
socket	B-Protocol
address	O
pair	O
of	O
this	O
connection	O
.	O
</s>
<s>
close( )	O
causes	O
the	O
system	O
to	O
release	O
resources	O
allocated	O
to	O
a	O
socket	B-Protocol
.	O
</s>
<s>
IPv4	B-Protocol
only	O
.	O
</s>
<s>
getaddrinfo( )	O
and	O
freeaddrinfo( )	O
are	O
used	O
to	O
resolve	O
host	O
names	O
and	O
addresses	O
.	O
</s>
<s>
IPv4	B-Protocol
,	O
IPv6	B-Protocol
.	O
</s>
<s>
poll( )	O
is	O
used	O
to	O
check	O
on	O
the	O
state	O
of	O
a	O
socket	B-Protocol
in	O
a	O
set	O
of	O
sockets	O
.	O
</s>
<s>
The	O
set	O
can	O
be	O
tested	O
to	O
see	O
if	O
any	O
socket	B-Protocol
can	O
be	O
written	O
to	O
,	O
read	O
from	O
or	O
if	O
an	O
error	O
occurred	O
.	O
</s>
<s>
getsockopt( )	O
is	O
used	O
to	O
retrieve	O
the	O
current	O
value	O
of	O
a	O
particular	O
socket	B-Protocol
option	O
for	O
the	O
specified	O
socket	B-Protocol
.	O
</s>
<s>
setsockopt( )	O
is	O
used	O
to	O
set	O
a	O
particular	O
socket	B-Protocol
option	O
for	O
the	O
specified	O
socket	B-Protocol
.	O
</s>
<s>
The	O
function	O
socket( )	O
creates	O
an	O
endpoint	O
for	O
communication	O
and	O
returns	O
a	O
file	B-Application
descriptor	I-Application
for	O
the	O
socket	B-Protocol
.	O
</s>
<s>
,	O
which	O
specifies	O
the	O
protocol	O
family	O
of	O
the	O
created	O
socket	B-Protocol
.	O
</s>
<s>
bind( )	O
associates	O
a	O
socket	B-Protocol
with	O
an	O
address	O
.	O
</s>
<s>
When	O
a	O
socket	B-Protocol
is	O
created	O
with	O
socket( )	O
,	O
it	O
is	O
only	O
given	O
a	O
protocol	O
family	O
,	O
but	O
not	O
assigned	O
an	O
address	O
.	O
</s>
<s>
This	O
association	O
must	O
be	O
performed	O
before	O
the	O
socket	B-Protocol
can	O
accept	O
connections	O
from	O
other	O
hosts	O
.	O
</s>
<s>
After	O
a	O
socket	B-Protocol
has	O
been	O
associated	O
with	O
an	O
address	O
,	O
listen( )	O
prepares	O
it	O
for	O
incoming	O
connections	O
.	O
</s>
<s>
However	O
,	O
this	O
is	O
only	O
necessary	O
for	O
the	O
stream-oriented	O
(	O
connection-oriented	B-Protocol
)	O
data	O
modes	O
,	O
i.e.	O
,	O
for	O
socket	B-Protocol
types	O
(	O
SOCK_STREAM	O
,	O
SOCK_SEQPACKET	O
)	O
.	O
</s>
<s>
sockfd	O
,	O
a	O
valid	O
socket	B-Protocol
descriptor	O
.	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
usually	O
places	O
a	O
cap	O
on	O
this	O
value	O
.	O
</s>
<s>
It	O
creates	O
a	O
new	O
socket	B-Protocol
for	O
each	O
connection	O
and	O
removes	O
the	O
connection	O
from	O
the	O
listening	O
queue	O
.	O
</s>
<s>
sockfd	O
,	O
the	O
descriptor	O
of	O
the	O
listening	O
socket	B-Protocol
that	O
has	O
the	O
connection	O
queued	O
.	O
</s>
<s>
accept( )	O
returns	O
the	O
new	O
socket	B-Protocol
descriptor	O
for	O
the	O
accepted	O
connection	O
,	O
or	O
the	O
value	O
-1	O
if	O
an	O
error	O
occurs	O
.	O
</s>
<s>
All	O
further	O
communication	O
with	O
the	O
remote	O
host	O
now	O
occurs	O
via	O
this	O
new	O
socket	B-Protocol
.	O
</s>
<s>
Datagram	B-Protocol
sockets	I-Protocol
do	O
not	O
require	O
processing	O
by	O
accept( )	O
since	O
the	O
receiver	O
may	O
immediately	O
respond	O
to	O
the	O
request	O
using	O
the	O
listening	O
socket	B-Protocol
.	O
</s>
<s>
connect( )	O
establishes	O
a	O
direct	O
communication	O
link	O
to	O
a	O
specific	O
remote	O
host	O
identified	O
by	O
its	O
address	O
via	O
a	O
socket	B-Protocol
,	O
identified	O
by	O
its	O
file	B-Application
descriptor	I-Application
.	O
</s>
<s>
When	O
using	O
a	O
connection-oriented	B-Protocol
protocol	I-Protocol
,	O
this	O
establishes	O
a	O
connection	O
.	O
</s>
<s>
Certain	O
types	O
of	O
protocols	O
are	O
connectionless	B-Protocol
,	O
most	O
notably	O
the	O
User	B-Protocol
Datagram	I-Protocol
Protocol	I-Protocol
.	O
</s>
<s>
When	O
used	O
with	O
connectionless	B-Protocol
protocols	I-Protocol
,	O
connect	O
defines	O
the	O
remote	O
address	O
for	O
sending	O
and	O
receiving	O
data	O
,	O
allowing	O
the	O
use	O
of	O
functions	O
such	O
as	O
send	O
and	O
recv	O
.	O
</s>
<s>
Historically	O
,	O
in	O
BSD-derived	O
systems	O
,	O
the	O
state	O
of	O
a	O
socket	B-Protocol
descriptor	O
is	O
undefined	O
if	O
the	O
call	O
to	O
connect	O
fails	O
(	O
as	O
it	O
is	O
specified	O
in	O
the	O
Single	O
Unix	B-Application
Specification	O
)	O
,	O
thus	O
,	O
portable	O
applications	O
should	O
close	O
the	O
socket	B-Protocol
descriptor	O
immediately	O
and	O
obtain	O
a	O
new	O
descriptor	O
with	O
socket( )	O
,	O
in	O
the	O
case	O
the	O
call	O
to	O
connect( )	O
fails	O
.	O
</s>
<s>
The	O
functions	O
gethostbyname( )	O
and	O
gethostbyaddr( )	O
are	O
used	O
to	O
resolve	O
host	O
names	O
and	O
addresses	O
in	O
the	O
domain	B-Protocol
name	I-Protocol
system	I-Protocol
or	O
the	O
local	O
host	O
's	O
other	O
resolver	O
mechanisms	O
(	O
e.g.	O
,	O
/etc/hosts	O
lookup	O
)	O
.	O
</s>
<s>
They	O
return	O
a	O
pointer	O
to	O
an	O
object	O
of	O
type	O
struct	O
hostent	O
,	O
which	O
describes	O
an	O
Internet	B-Protocol
Protocol	I-Protocol
host	O
.	O
</s>
<s>
These	O
functions	O
are	O
not	O
strictly	O
a	O
component	O
of	O
the	O
BSD	B-Protocol
socket	I-Protocol
API	I-Protocol
,	O
but	O
are	O
often	O
used	O
in	O
conjunction	O
with	O
the	O
API	B-Application
functions	I-Application
for	O
looking	O
up	O
a	O
host	O
.	O
</s>
<s>
These	O
functions	O
are	O
now	O
considered	O
legacy	O
interfaces	O
for	O
querying	O
the	O
domain	B-Protocol
name	I-Protocol
system	I-Protocol
.	O
</s>
<s>
New	O
functions	O
that	O
are	O
completely	O
protocol-agnostic	O
(	O
supporting	O
IPv6	B-Protocol
)	O
have	O
been	O
defined	O
.	O
</s>
<s>
These	O
new	O
functions	O
are	O
getaddrinfo( )	O
and	O
getnameinfo( )	O
,	O
and	O
are	O
based	O
on	O
a	O
new	O
addrinfo	O
data	O
structure	O
.	O
</s>
<s>
This	O
pair	O
of	O
functions	O
appeared	O
at	O
the	O
same	O
time	O
as	O
the	O
BSD	B-Protocol
socket	I-Protocol
API	I-Protocol
proper	O
in	O
4.2BSD	O
(	O
1983	O
)	O
,	O
the	O
same	O
year	O
DNS	B-Protocol
was	O
first	O
created	O
.	O
</s>
<s>
Early	O
versions	O
did	O
not	O
query	O
DNS	B-Protocol
and	O
only	O
performed	O
/etc/hosts	O
lookup	O
.	O
</s>
<s>
The	O
4.3BSD	O
(	O
1984	O
)	O
version	O
added	O
DNS	B-Protocol
in	O
a	O
crude	O
way	O
.	O
</s>
<s>
The	O
current	O
implementation	O
using	O
Name	B-Protocol
Service	I-Protocol
Switch	I-Protocol
derives	O
Solaris	O
and	O
later	O
NetBSD	O
1.4	O
(	O
1999	O
)	O
.	O
</s>
<s>
Initially	O
defined	O
for	O
NIS+	O
,	O
NSS	O
makes	O
DNS	B-Protocol
only	O
one	O
of	O
the	O
many	O
options	O
for	O
lookup	O
by	O
these	O
functions	O
and	O
its	O
use	O
can	O
be	O
disabled	O
even	O
today	O
.	O
</s>
<s>
The	O
Berkeley	B-Protocol
socket	I-Protocol
API	I-Protocol
is	O
a	O
general	O
interface	O
for	O
networking	O
and	O
interprocess	B-Operating_System
communication	I-Operating_System
,	O
and	O
supports	O
the	O
use	O
of	O
various	O
network	O
protocols	O
and	O
address	O
architectures	O
.	O
</s>
<s>
The	O
following	O
lists	O
a	O
sampling	O
of	O
protocol	O
families	O
(	O
preceded	O
by	O
the	O
standard	O
symbolic	O
identifier	O
)	O
defined	O
in	O
a	O
modern	O
Linux	B-Application
or	O
BSD	B-Operating_System
implementation	O
:	O
</s>
<s>
A	O
socket	B-Protocol
for	O
communications	O
is	O
created	O
with	O
the	O
function	O
,	O
by	O
specifying	O
the	O
desired	O
protocol	O
family	O
(	O
-identifier	O
)	O
as	O
an	O
argument	O
.	O
</s>
<s>
The	O
original	O
design	O
concept	O
of	O
the	O
socket	B-Protocol
interface	O
distinguished	O
between	O
protocol	O
types	O
(	O
families	O
)	O
and	O
the	O
specific	O
address	O
types	O
that	O
each	O
may	O
use	O
.	O
</s>
<s>
Raw	B-Protocol
sockets	I-Protocol
provide	O
a	O
simple	O
interface	O
that	O
bypasses	O
the	O
processing	O
by	O
the	O
host	O
's	O
TCP/IP	O
stack	O
.	O
</s>
<s>
They	O
permit	O
implementation	O
of	O
networking	O
protocols	O
in	O
user	B-Operating_System
space	I-Operating_System
and	O
aid	O
in	O
debugging	O
of	O
the	O
protocol	O
stack	O
.	O
</s>
<s>
Raw	B-Protocol
sockets	I-Protocol
are	O
used	O
by	O
some	O
services	O
,	O
such	O
as	O
ICMP	B-Protocol
,	O
that	O
operate	O
at	O
the	O
Internet	B-Protocol
Layer	I-Protocol
of	O
the	O
TCP/IP	O
model	O
.	O
</s>
<s>
Berkeley	B-Protocol
sockets	I-Protocol
can	O
operate	O
in	O
one	O
of	O
two	O
modes	O
:	O
blocking	B-Operating_System
or	O
non-blocking	O
.	O
</s>
<s>
A	O
blocking	B-Operating_System
socket	B-Protocol
does	O
not	O
return	O
control	O
until	O
it	O
has	O
sent	O
(	O
or	O
received	O
)	O
some	O
or	O
all	O
data	O
specified	O
for	O
the	O
operation	O
.	O
</s>
<s>
It	O
is	O
normal	O
for	O
a	O
blocking	B-Operating_System
socket	B-Protocol
not	O
to	O
send	O
all	O
data	O
.	O
</s>
<s>
When	O
using	O
blocking	B-Operating_System
sockets	O
,	O
special	O
consideration	O
should	O
be	O
given	O
to	O
accept( )	O
as	O
it	O
may	O
still	O
block	O
after	O
indicating	O
readability	O
if	O
a	O
client	O
disconnects	O
during	O
the	O
connection	O
phase	O
.	O
</s>
<s>
A	O
non-blocking	O
socket	B-Protocol
returns	O
whatever	O
is	O
in	O
the	O
receive	O
buffer	O
and	O
immediately	O
continues	O
.	O
</s>
<s>
If	O
not	O
written	O
correctly	O
,	O
programs	O
using	O
non-blocking	O
sockets	O
are	O
particularly	O
susceptible	O
to	O
race	B-Operating_System
conditions	I-Operating_System
due	O
to	O
variances	O
in	O
network	O
link	O
speed	O
.	O
</s>
<s>
A	O
socket	B-Protocol
is	O
typically	O
set	O
to	O
blocking	B-Operating_System
or	O
non-blocking	O
mode	O
using	O
the	O
functions	O
fcntl	B-Application
and	O
ioctl	B-Operating_System
.	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
does	O
not	O
release	O
the	O
resources	O
allocated	O
to	O
a	O
socket	B-Protocol
until	O
the	O
socket	B-Protocol
is	O
closed	O
.	O
</s>
<s>
When	O
an	O
application	O
closes	O
a	O
socket	B-Protocol
,	O
only	O
the	O
interface	O
to	O
the	O
socket	B-Protocol
is	O
destroyed	O
.	O
</s>
<s>
It	O
is	O
the	O
kernel	O
's	O
responsibility	O
to	O
destroy	O
the	O
socket	B-Protocol
internally	O
.	O
</s>
<s>
Sometimes	O
,	O
a	O
socket	B-Protocol
may	O
enter	O
a	O
state	O
,	O
on	O
the	O
server	O
side	O
,	O
for	O
up	O
to	O
4	O
minutes	O
.	O
</s>
<s>
The	O
Transmission	B-Protocol
Control	I-Protocol
Protocol	I-Protocol
(	O
TCP	O
)	O
is	O
a	O
connection-oriented	B-Protocol
protocol	I-Protocol
that	O
provides	O
a	O
variety	O
of	O
error	O
correction	O
and	O
performance	O
features	O
for	O
transmission	O
of	O
byte	O
streams	B-Operating_System
.	O
</s>
<s>
A	O
process	O
creates	O
a	O
TCP	B-Protocol
socket	I-Protocol
by	O
calling	O
the	O
function	O
with	O
the	O
parameters	O
for	O
the	O
protocol	O
family	O
(	O
)	O
,	O
the	O
socket	B-Protocol
mode	O
for	O
Stream	O
Sockets	O
(	O
)	O
,	O
and	O
the	O
IP	B-Protocol
protocol	I-Protocol
identifier	O
for	O
TCP	O
(	O
)	O
.	O
</s>
<s>
Creating	O
a	O
TCP	B-Protocol
socket	I-Protocol
with	O
a	O
call	O
to	O
socket( )	O
.	O
</s>
<s>
Binding	O
the	O
socket	B-Protocol
to	O
the	O
listening	O
port	O
(bind( )	O
)	O
after	O
setting	O
the	O
port	O
number	O
.	O
</s>
<s>
Preparing	O
the	O
socket	B-Protocol
to	O
listen	O
for	O
connections	O
(	O
making	O
it	O
a	O
listening	O
socket	B-Protocol
)	O
,	O
with	O
a	O
call	O
to	O
listen( )	O
.	O
</s>
<s>
This	O
blocks	O
the	O
process	O
until	O
an	O
incoming	O
connection	O
is	O
received	O
,	O
and	O
returns	O
a	O
socket	B-Protocol
descriptor	O
for	O
the	O
accepted	O
connection	O
.	O
</s>
<s>
The	O
initial	O
descriptor	O
remains	O
a	O
listening	O
descriptor	O
,	O
and	O
accept( )	O
can	O
be	O
called	O
again	O
at	O
any	O
time	O
with	O
this	O
socket	B-Protocol
,	O
until	O
it	O
is	O
closed	O
.	O
</s>
<s>
Communicating	O
with	O
the	O
remote	O
host	O
with	O
the	O
API	B-Application
functions	I-Application
send( )	O
and	O
recv( )	O
,	O
as	O
well	O
as	O
with	O
the	O
general-purpose	O
functions	O
write( )	O
and	O
read( )	O
.	O
</s>
<s>
Creating	O
a	O
TCP	B-Protocol
socket	I-Protocol
.	O
</s>
<s>
Communicating	O
with	O
the	O
remote	O
host	O
with	O
the	O
API	B-Application
functions	I-Application
send( )	O
and	O
recv( )	O
,	O
as	O
well	O
as	O
with	O
the	O
general-purpose	O
functions	O
write( )	O
and	O
read( )	O
.	O
</s>
<s>
Closing	O
each	O
socket	B-Protocol
that	O
was	O
opened	O
after	O
use	O
with	O
function	O
close( )	O
.	O
</s>
<s>
The	O
User	B-Protocol
Datagram	I-Protocol
Protocol	I-Protocol
(	O
UDP	O
)	O
is	O
a	O
connectionless	B-Protocol
protocol	I-Protocol
with	O
no	O
guarantee	O
of	O
delivery	O
.	O
</s>
<s>
UDP	B-Protocol
packets	I-Protocol
may	O
arrive	O
out	O
of	O
order	O
,	O
multiple	O
times	O
,	O
or	O
not	O
at	O
all	O
.	O
</s>
<s>
Being	O
connectionless	B-Protocol
means	O
that	O
there	O
is	O
no	O
concept	O
of	O
a	O
stream	O
or	O
permanent	O
connection	O
between	O
two	O
hosts	O
.	O
</s>
<s>
Such	O
data	O
are	O
referred	O
to	O
as	O
datagrams	O
(	O
Datagram	B-Protocol
Sockets	I-Protocol
)	O
.	O
</s>
<s>
UDP	O
address	O
space	O
,	O
the	O
space	O
of	O
UDP	O
port	O
numbers	O
(	O
in	O
ISO	O
terminology	O
,	O
the	O
TSAPs	B-Protocol
)	O
,	O
is	O
completely	O
disjoint	O
from	O
that	O
of	O
TCP	O
ports	O
.	O
</s>
<s>
The	O
following	O
is	O
a	O
client	O
program	O
for	O
sending	O
a	O
UDP	B-Protocol
packet	I-Protocol
containing	O
the	O
string	O
"	O
Hello	O
World	O
!	O
"	O
</s>
