ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzab6_5.4.0.1/howdosockets.htm

120 lines
8.8 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="concept" />
<meta name="DC.Title" content="How sockets work" />
<meta name="abstract" content="Sockets are commonly used for client/server interaction. Typical system configuration places the server on one machine, with the clients on other machines. The clients connect to the server, exchange information, and then disconnect." />
<meta name="description" content="Sockets are commonly used for client/server interaction. Typical system configuration places the server on one machine, with the clients on other machines. The clients connect to the server, exchange information, and then disconnect." />
<meta name="DC.Relation" scheme="URI" content="rzab6soxoverview.htm" />
<meta name="DC.Relation" scheme="URI" content="cbsd.htm" />
<meta name="DC.Relation" scheme="URI" content="cunix98.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/socket.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/listen.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/bind.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/accept.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/send.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/recv.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/close.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/unix8.htm" />
<meta name="DC.Relation" scheme="URI" content="../apifinder/finder.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="howdosockets" />
<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>How sockets work</title>
</head>
<body id="howdosockets"><a name="howdosockets"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">How sockets work</h1>
<div><p>Sockets are commonly used for client/server interaction. Typical
system configuration places the server on one machine, with the clients on
other machines. The clients connect to the server, exchange information, and
then disconnect.</p>
<p>A socket has a typical flow of events. In a connection-oriented client-to-server
model, the socket on the server process waits for requests from a client.
To do this, the server first establishes (binds) an address that clients can
use to find the server. When the address is established, the server waits
for clients to request a service. The client-to-server data exchange takes
place when a client connects to the server through a socket. The server performs
the client's request and sends the reply back to the client.</p>
<div class="note"><span class="notetitle">Note:</span> Currently, IBM<sup>®</sup> supports two versions of most sockets APIs. The default i5/OS™ sockets
use Berkeley Socket Distribution (BSD) 4.3 structures and syntax. The other
version of sockets uses syntax and structures compatible with BSD 4.4 and
the UNIX<sup>®</sup> 98
programming interface specifications. Programmers can specify _XOPEN_SOURCE
macro to use the UNIX 98 compatible interface.</div>
<p>The following figure shows the typical flow of events (and the sequence
of issued functions) for a connection-oriented socket session. An explanation
of each event follows the figure.</p>
<br /><img src="rxab6500.gif" alt="The two endpoints establish a connection, and bring the client and server together." /><br /><p>Typical flow of events for a connection-oriented socket:</p>
<ol><li>The <span class="apiname">socket()</span> function creates an endpoint for communications
and returns a socket descriptor that represents the endpoint.</li>
<li>When an application has a socket descriptor, it can bind a unique name
to the socket. Servers must bind a name to be accessible from the network.</li>
<li>The <span class="apiname">listen()</span> function indicates a willingness to accept
client connection requests. When a <span class="apiname">listen()</span> is issued for
a socket, that socket cannot actively initiate connection requests. The <span class="apiname">listen()</span> API
is issued after a socket is allocated with a <span class="apiname">socket()</span> function
and the <span class="apiname">bind()</span> function binds a name to the socket. A <span class="apiname">listen()</span> function
must be issued before an <span class="apiname">accept()</span> function is issued.</li>
<li>The client application uses a <span class="apiname">connect()</span> function on
a stream socket to establish a connection to the server.</li>
<li>The server application uses the <span class="apiname">accept()</span> function to
accept a client connection request. The server must issue the<span class="apiname"> bind()</span> and
<span class="apiname">listen()</span> functions successfully before it can issue an <span class="apiname">accept()</span>.</li>
<li>When a connection is established between stream sockets (between client
and server), you can use any of the socket API data transfer functions. Clients
and servers have many data transfer functions from which to choose, such as <span class="apiname">send()</span>, <span class="apiname">recv()</span>, <span class="apiname">read()</span>, <span class="apiname">write()</span>, and others.</li>
<li>When a server or client wants to cease operations, it issues a <span class="apiname">close()</span> function
to release any system resources acquired by the socket.</li>
</ol>
<div class="note"><span class="notetitle">Note:</span> The socket APIs are located in the communications model between the
application layer and the transport layer. The socket APIs are not a layer
in the communication model. Socket APIs allow applications to interact with
the transport or networking layers of the typical communications model. The
arrows in the following figure show the position of a socket, and the communication
layer that the socket provides. <br /><img src="rxab6501.gif" alt="Position of a socket in the communication layer" /><br /></div>
<p>Typically, a network configuration does not allow connections between a
secure internal network and a less secure external network. However, you can
enable sockets to communicate with server programs that run on a system outside
a firewall (a very secure host).</p>
<p>Sockets are also a part of IBM's AnyNet<sup>®</sup> implementation for the Multiprotocol
Transport Networking (MPTN) architecture. MPTN architecture provides the ability
to operate a transport network over additional transport networks and to connect
application programs across transport networks of different types.</p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzab6soxoverview.htm" title="A socket is a communications connection point (endpoint) that you can name and address in a network.">Socket programming</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="cbsd.htm" title="Sockets is a Berkeley Software Distribution (BSD) interface.">Berkeley Software Distribution compatibility</a></div>
<div><a href="cunix98.htm" title="Created by The Open Group, a consortium of developers and venders, UNIX 98 improved the inter-operability of the UNIX operating system while incorporating much of the Internet-related function for which UNIX had become known.">UNIX 98 compatibility</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../apis/socket.htm">socket()</a></div>
<div><a href="../apis/listen.htm">listen()</a></div>
<div><a href="../apis/bind.htm">bind()</a></div>
<div><a href="../apis/accept.htm">accept()</a></div>
<div><a href="../apis/send.htm">send()</a></div>
<div><a href="../apis/recv.htm">recv()</a></div>
<div><a href="../apis/close.htm">close()</a></div>
<div><a href="../apis/unix8.htm">Socket APIs</a></div>
<div><a href="../apifinder/finder.htm">API finder</a></div>
</div>
</div>
</body>
</html>