132 lines
9.2 KiB
HTML
132 lines
9.2 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: Connection-oriented designs" />
|
|
<meta name="abstract" content="There are a number of ways that you can design a connection-oriented socket server on the iSeries. These example programs can be used to create your own connection-oriented designs." />
|
|
<meta name="description" content="There are a number of ways that you can design a connection-oriented socket server on the iSeries. These example programs can be used to create your own connection-oriented designs." />
|
|
<meta name="DC.Relation" scheme="URI" content="example.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xiterative.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xspawn.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xdescriptors.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xmultiaccept.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="generic.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xacceptboth.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="asynchi0.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xasynchi0.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="generic.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/accept.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/spawn.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="xcodesigns" />
|
|
<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: Connection-oriented designs</title>
|
|
</head>
|
|
<body id="xcodesigns"><a name="xcodesigns"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Examples: Connection-oriented designs</h1>
|
|
<div><p>There are a number of ways that you can design a connection-oriented
|
|
socket server on the iSeries™. These example programs can be used to create
|
|
your own connection-oriented designs.</p>
|
|
<div class="section"><p>While additional socket server designs are possible,
|
|
the designs provided in these examples are the most common.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Iterative server</h4><p>In the iterative server example,
|
|
a single server job handles all incoming connections and all data flows with
|
|
the client jobs. When the <span class="apiname">accept()</span> API is completed, the
|
|
server handles the entire transaction. This is the easiest server to develop,
|
|
but it does have a few problems. While the server is handling the request
|
|
from a given client, additional clients can be trying to get to the server.
|
|
These requests fill the <span class="apiname">listen()</span> backlog and some of the
|
|
them are rejected eventually.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Concurrent server</h4><p>In the concurrent
|
|
server designs, the system uses multiple jobs and threads to handle the incoming
|
|
connection requests. With a concurrent server there are typically multiple
|
|
clients that connect to the server at the same time.</p>
|
|
<p>For
|
|
multiple concurrent clients in a network, it is recommended that
|
|
you use the asynchronous I/O socket APIs. These APIs provide the best performance
|
|
in networks that have multiple concurrent clients. </p>
|
|
<ul><li><span class="apiname">spawn()</span> server and <span class="apiname">spawn()</span> worker<p>The <span class="apiname">spawn()</span> API is used to create a new
|
|
job to handle each incoming request. After <span class="apiname">spawn()</span> is completed,
|
|
the server can wait on the <span class="apiname">accept()</span> API for the next incoming
|
|
connection to be received.</p>
|
|
<p>The only problem with this server design
|
|
is the performance overhead of creating a new job each time a connection is
|
|
received. You can avoid the performance overhead of the <span class="apiname">spawn()</span> server
|
|
example by using prestarted jobs. Instead of creating a new job each time
|
|
a connection is received, the incoming connection is given to a job that is
|
|
already active. All of the remaining examples in this topic use prestarted
|
|
jobs.</p>
|
|
</li>
|
|
<li><span class="apiname">sendmsg()</span> server and <span class="apiname">recvmsg()</span> worker<p>The <span class="apiname">sendmsg()</span> and <span class="apiname">recvmsg()</span> APIs are used to handle incoming connections. The server prestarts all of
|
|
the worker jobs when the server job first starts.</p>
|
|
</li>
|
|
<li>Multiple <span class="apiname">accept()</span> servers and multiple <span class="apiname">accept()</span> workers<p>For
|
|
the previous APIs, the worker job does not get involved until after the server
|
|
receives the incoming connection request. When the multiple <span class="apiname">accept()</span> APIs
|
|
are used, each of the worker jobs can be turned into an iterative server.
|
|
The server job still calls the <span class="apiname">socket()</span>, <span class="apiname">bind()</span>,
|
|
and <span class="apiname">listen()</span> APIs. When the <span class="apiname">listen()</span> call
|
|
is completed, the server creates each of the worker jobs and gives a listening
|
|
socket to each one of them. All of the worker jobs then call the <span class="apiname">accept()</span> API.
|
|
When a client tries to connect to the server, only one <span class="apiname">accept()</span> call
|
|
is completed, and that worker handles the connection.</p>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<ul class="ullinks">
|
|
<li class="ulchildlink"><strong><a href="xiterative.htm">Example: Write an iterative server program</a></strong><br />
|
|
Use this example to create a single server job that handles all
|
|
incoming connections. When the <span class="apiname">accept()</span> API is completed,
|
|
the server handles the entire transaction.</li>
|
|
<li class="ulchildlink"><strong><a href="xspawn.htm">Example: Use the spawn() API to create child processes</a></strong><br />
|
|
This example shows how a server program can use the <span class="apiname">spawn()</span> API
|
|
to create a child process that inherits the socket descriptor from the parent. </li>
|
|
<li class="ulchildlink"><strong><a href="xdescriptors.htm">Example: Pass descriptors between processes</a></strong><br />
|
|
The <span class="apiname">sendmsg()</span> and <span class="apiname">recvmsg()</span> examples
|
|
show how to design a server program that uses these APIs to handle incoming
|
|
connections.</li>
|
|
<li class="ulchildlink"><strong><a href="xmultiaccept.htm">Examples: Use multiple accept() APIs to handle incoming requests</a></strong><br />
|
|
These examples show how to design a server program that uses the
|
|
multiple <span class="apiname">accept()</span> model for handling incoming connection
|
|
requests.</li>
|
|
<li class="ulchildlink"><strong><a href="generic.htm">Example: Generic client</a></strong><br />
|
|
This code example contains the code for a common client job.</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="asynchi0.htm" title="Asynchronous I/O APIs provide a method for threaded client server models to perform highly concurrent and memory efficient I/O.">Asynchronous I/O</a></div>
|
|
</div>
|
|
<div class="relref"><strong>Related reference</strong><br />
|
|
<div><a href="xacceptboth.htm" title="Use this sample program to create a server/client model that accepts requests from both IPv4 (those socket applications that use the AF_INET address family) and IPv6 (those applications that use the AF_INET6 address family).">Example: Accept connections from both IPv6 and IPv4 clients</a></div>
|
|
<div><a href="xasynchi0.htm" title="An application creates an I/O completion port using the QsoCreateIOCompletionPort() API.">Example: Use asynchronous I/O</a></div>
|
|
<div><a href="generic.htm" title="This code example contains the code for a common client job.">Example: Generic client</a></div>
|
|
</div>
|
|
<div class="relinfo"><strong>Related information</strong><br />
|
|
<div><a href="../apis/accept.htm">accept()</a></div>
|
|
<div><a href="../apis/spawn.htm">spawn()</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |