149 lines
9.4 KiB
HTML
149 lines
9.4 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Examples: Use multicasting with AF_INET" />
|
||
|
<meta name="abstract" content="IP multicasting provides the capability for an application to send a single IP datagram that a group of hosts in a network can receive." />
|
||
|
<meta name="description" content="IP multicasting provides the capability for an application to send a single IP datagram that a group of hosts in a network can receive." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="example.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="x1multicast.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="x2multicast.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="cmulticast.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="x1multicast.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/close.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/socket.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/bind.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/ssocko.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/read.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/sendto.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2001, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2001, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="xmulticast" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Examples: Use multicasting with AF_INET</title>
|
||
|
</head>
|
||
|
<body id="xmulticast"><a name="xmulticast"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Examples: Use multicasting with AF_INET</h1>
|
||
|
<div><p>IP multicasting provides the capability for an application to send
|
||
|
a single IP datagram that a group of hosts in a network can receive. </p>
|
||
|
<div class="section"><p>The hosts that are in the group might reside on
|
||
|
a single subnet or on different subnets that connect multicast-capable routers.
|
||
|
Hosts might join and leave groups at any time. There are no restrictions on
|
||
|
the location or number of members in a host group. A class D IP address in
|
||
|
the range 224.0.0.1 to 239.255.255.255 identifies a host group.</p>
|
||
|
</div>
|
||
|
<div class="section"><p>An application program can send or receive multicast datagrams
|
||
|
by using the <span class="apiname">socket()</span> API and connectionless SOCK_DGRAM
|
||
|
type sockets. Multicasting is a one-to-many transmission method. You cannot
|
||
|
use connection-oriented sockets of type SOCK_STREAM for multicasting. When
|
||
|
a socket of type SOCK_DGRAM is created, an application can use the <span class="apiname">setsockopt()</span> function
|
||
|
to control the multicast characteristics associated with that socket. The <span class="apiname">setsockopt()</span> function
|
||
|
accepts the following IPPROTO_IP level flags: </p>
|
||
|
<ul><li>IP_ADD_MEMBERSHIP: Joins the multicast group specified.</li>
|
||
|
<li>IP_DROP_MEMBERSHIP: Leaves the multicast group specified.</li>
|
||
|
<li>IP_MULTICAST_IF: Sets the interface over which outgoing multicast datagrams
|
||
|
are sent.</li>
|
||
|
<li>IP_MULTICAST_TTL: Sets the Time To Live (TTL) in the IP header for outgoing
|
||
|
multicast datagrams.</li>
|
||
|
<li>IP_MULTICAST_LOOP: Specifies whether a copy of an outgoing multicast datagram
|
||
|
is delivered to the sending host as long as it is a member of the multicast
|
||
|
group.</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="section"><div class="p"> <div class="note"><span class="notetitle">Note:</span> i5/OS™ sockets support IP multicasting for
|
||
|
the AF_INET address family.</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section"><p><br /><img src="rzab6507.gif" alt="This graphic shows the flow of socket calls that are used for IP multicasting with AF_INET address family." /><br /></p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Socket flow of events: Sending multicast datagrams</h4><p>The
|
||
|
following sequence of the socket calls provides a description of the graphic.
|
||
|
It also describes the relationship between two applications that send and
|
||
|
receive multicast datagrams. The first example uses the following sequence
|
||
|
of function calls:</p>
|
||
|
<ol><li>The <span class="apiname">socket()</span> function returns a socket descriptor representing
|
||
|
an endpoint. The statement also identifies that the INET (Internet Protocol)
|
||
|
address family with the TCP transport (SOCK_DGRAM) is used for this socket.
|
||
|
This socket sends datagrams to another application.</li>
|
||
|
<li>The sockaddr_in structure specifies the destination IP address and port
|
||
|
number. In this example, the address is 225.1.1.1 and the port number is 5555.</li>
|
||
|
<li>The <span class="apiname">setsockopt()</span> function sets the IP_MULTICAST_LOOP
|
||
|
socket option so that the sending system does not receive a copy of the multicast
|
||
|
datagrams it transmits.</li>
|
||
|
<li>The <span class="apiname">setsockopt()</span> function uses the IP_MULTICAST_IF
|
||
|
socket option which defines the local interface over which the multicast datagrams
|
||
|
are sent.</li>
|
||
|
<li>The <span class="apiname">sendto()</span> function sends multicast datagrams to
|
||
|
the specified group IP addresses.</li>
|
||
|
<li>The <span class="apiname">close()</span> function closes any open socket descriptors.</li>
|
||
|
</ol>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">Socket flow of events: Receive multicast datagrams</h4><p>The
|
||
|
second example uses the following sequence of function calls:</p>
|
||
|
<ol><li>The <span class="apiname">socket()</span> function returns a socket descriptor representing
|
||
|
an endpoint. The statement also identifies that the INET (Internet Protocol)
|
||
|
address family with the TCP transport (SOCK_DGRAM) is used for this socket.
|
||
|
This socket sends datagrams to another application.</li>
|
||
|
<li>The <span class="apiname">setsockopt()</span> function sets the SO_REUSEADDR socket
|
||
|
option to allow multiple applications to receive datagrams that are destined
|
||
|
to the same local port number.</li>
|
||
|
<li>The <span class="apiname">bind()</span> function specifies the local port number.
|
||
|
In this example, the IP address is specified as INADDR_ANY to receive datagrams
|
||
|
that are addressed to the multicast group.</li>
|
||
|
<li>The <span class="apiname">setsockopt()</span> function uses the IP_ADD_MEMBERSHIP
|
||
|
socket option which joins the multicast group that receives the datagrams.
|
||
|
When joining a group, specify the class D group address along with the IP
|
||
|
address of a local interface. The system must call the IP_ADD_MEMBERSHIP socket
|
||
|
option for each local interface receiving the multicast datagrams. In this
|
||
|
example, the multicast group (225.1.1.1) is joined on the local 9.5.1.1 interface.
|
||
|
<div class="note"><span class="notetitle">Note:</span> IP_ADD_MEMBERSHIP option must be called for each local interface over
|
||
|
which the multicast datagrams are to be received.</div>
|
||
|
</li>
|
||
|
<li>The <span class="apiname">read()</span> function reads multicast datagrams that
|
||
|
are being sent..</li>
|
||
|
<li>The <span class="apiname">close()</span> function closes any open socket descriptors.</li>
|
||
|
</ol>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="x1multicast.htm">Example: Send multicast datagrams</a></strong><br />
|
||
|
This example enables a socket to send multicast datagrams.</li>
|
||
|
<li class="ulchildlink"><strong><a href="x2multicast.htm">Example: Receive multicast datagrams</a></strong><br />
|
||
|
This example enables a socket to receive multicast datagrams.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="example.htm" title="These examples provide many sample programs that illustrate the more advanced socket concepts. You can use these sample programs to create your own applications that complete a similar task.">Examples: Socket application designs</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="cmulticast.htm" title="IP multicasting allows an application to send a single IP datagram that a group of hosts in a network can receive.">IP multicasting</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="x1multicast.htm" title="This example enables a socket to send multicast datagrams.">Example: Send multicast datagrams</a></div>
|
||
|
</div>
|
||
|
<div class="relinfo"><strong>Related information</strong><br />
|
||
|
<div><a href="../apis/close.htm">close()</a></div>
|
||
|
<div><a href="../apis/socket.htm">socket()</a></div>
|
||
|
<div><a href="../apis/bind.htm">bind()</a></div>
|
||
|
<div><a href="../apis/ssocko.htm">setsockopt</a></div>
|
||
|
<div><a href="../apis/read.htm">read()</a></div>
|
||
|
<div><a href="../apis/sendto.htm">sendto()</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|