aboutsummaryrefslogtreecommitdiff
path: root/zh_TW.Big5/books/developers-handbook/sockets/chapter.xml
diff options
context:
space:
mode:
Diffstat (limited to 'zh_TW.Big5/books/developers-handbook/sockets/chapter.xml')
-rw-r--r--zh_TW.Big5/books/developers-handbook/sockets/chapter.xml83
1 files changed, 36 insertions, 47 deletions
diff --git a/zh_TW.Big5/books/developers-handbook/sockets/chapter.xml b/zh_TW.Big5/books/developers-handbook/sockets/chapter.xml
index aa2eed2c9f..06cc5a6f11 100644
--- a/zh_TW.Big5/books/developers-handbook/sockets/chapter.xml
+++ b/zh_TW.Big5/books/developers-handbook/sockets/chapter.xml
@@ -4,21 +4,16 @@
$FreeBSD$
-->
-
-<chapter id="sockets">
- <chapterinfo>
+<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:id="sockets">
+ <info><title>Sockets</title>
<authorgroup>
- <author>
- <firstname>G. Adam</firstname>
- <surname>Stanislav</surname>
- <contrib>Contributed by </contrib>
- </author>
+ <author><personname><firstname>G. Adam</firstname><surname>Stanislav</surname></personname><contrib>Contributed by </contrib></author>
</authorgroup>
- </chapterinfo>
+ </info>
- <title>Sockets</title>
+
- <sect1 id="sockets-synopsis">
+ <sect1 xml:id="sockets-synopsis">
<title>Synopsis</title>
<para><acronym>BSD</acronym> sockets take interprocess
@@ -45,7 +40,7 @@
</sect1>
- <sect1 id="sockets-diversity">
+ <sect1 xml:id="sockets-diversity">
<title>Networking and Diversity</title>
<para>We have already hinted on the <emphasis>diversity</emphasis>
@@ -85,7 +80,7 @@
</para>
</sect1>
- <sect1 id="sockets-protocols">
+ <sect1 xml:id="sockets-protocols">
<title>Protocols</title>
<para>While various programming languages tend to have complex
@@ -324,7 +319,7 @@
</sect1>
- <sect1 id="sockets-model">
+ <sect1 xml:id="sockets-model">
<title>The Sockets Model</title>
<para><acronym>BSD</acronym> sockets are built on the basic &unix;
@@ -349,7 +344,7 @@
</sect1>
- <sect1 id="sockets-essential-functions">
+ <sect1 xml:id="sockets-essential-functions">
<title>Essential Socket Functions</title>
<para>While FreeBSD offers different functions to work with
@@ -357,17 +352,17 @@
<quote>open</quote> a socket. And in some cases we only need
two.</para>
- <sect2 id="sockets-client-server">
+ <sect2 xml:id="sockets-client-server">
<title>The Client-Server Difference</title>
<para>Typically, one of the ends of a socket-based data
communication is a <emphasis>server</emphasis>, the other is a
<emphasis>client</emphasis>.</para>
- <sect3 id="sockets-common-elements">
+ <sect3 xml:id="sockets-common-elements">
<title>The Common Elements</title>
- <sect4 id="sockets-socket">
+ <sect4 xml:id="sockets-socket">
<title><function>socket</function></title>
<para>The one function used by both, clients and servers, is
@@ -418,7 +413,7 @@ int socket(int domain, int type, int protocol);
meaningful. In that case, use <constant>0</constant> for
its value.</para>
- <note id="sockets-unconnected">
+ <note xml:id="sockets-unconnected">
<title>The Unconnected Socket</title>
<para>Nowhere, in the <function>socket</function> function
@@ -434,7 +429,7 @@ int socket(int domain, int type, int protocol);
</sect4>
- <sect4 id="sockets-sockaddr">
+ <sect4 xml:id="sockets-sockaddr">
<title><varname>sockaddr</varname></title>
<para>Various functions of the sockets family expect the
@@ -598,10 +593,8 @@ struct sockaddr_in {
<constant>AF_INET</constant> in the address family
field. <constant>AF_INET</constant> is defined as
<constant>2</constant>. Let us use the
- <acronym>IP</acronym> address of <hostid
- role="ipaddr">192.43.244.18</hostid>, which is the time
- server of US federal government (<hostid
- role="domainname">time.nist.gov</hostid>).</para>
+ <acronym>IP</acronym> address of <systemitem class="ipaddress">192.43.244.18</systemitem>, which is the time
+ server of US federal government (<systemitem class="fqdomainname">time.nist.gov</systemitem>).</para>
<mediaobject>
<imageobject>
@@ -643,7 +636,7 @@ struct in_addr {
<para>In addition, <varname>in_addr_t</varname> is a 32-bit
integer.</para>
- <para>The <hostid role="ipaddr">192.43.244.18</hostid> is
+ <para>The <systemitem class="ipaddress">192.43.244.18</systemitem> is
just a convenient notation of expressing a 32-bit integer
by listing all of its 8-bit bytes, starting with the
<emphasis>most significant</emphasis> one.</para>
@@ -905,7 +898,7 @@ struct in_addr {
</sect3>
- <sect3 id="sockets-client-functions">
+ <sect3 xml:id="sockets-client-functions">
<title>Client Functions</title>
<para>Typically, the client initiates the connection to the
@@ -917,7 +910,7 @@ struct in_addr {
asking for the person in charge of wingdings (the
<emphasis>port</emphasis>).</para>
- <sect4 id="sockets-connect">
+ <sect4 xml:id="sockets-connect">
<title><function>connect</function></title>
<para>Once a client has created a socket, it needs to
@@ -952,13 +945,12 @@ int connect(int s, const struct sockaddr *name, socklen_t namelen);
</sect4>
- <sect4 id="sockets-first-client">
+ <sect4 xml:id="sockets-first-client">
<title>Our First Client</title>
<para>We now know enough to write a very simple client, one
- that will get current time from <hostid
- role="ipaddr">192.43.244.18</hostid> and print it to
- <devicename>stdout</devicename>.</para>
+ that will get current time from <systemitem class="ipaddress">192.43.244.18</systemitem> and print it to
+ <filename>stdout</filename>.</para>
<programlisting>
/*
@@ -1019,7 +1011,7 @@ int main() {
</sect3>
- <sect3 id="sockets-server-functions">
+ <sect3 xml:id="sockets-server-functions">
<title>Server Functions</title>
<para>The typical server does not initiate the
@@ -1033,7 +1025,7 @@ int main() {
<para>The sockets interface offers three basic functions to
handle this.</para>
- <sect4 id="sockets-bind">
+ <sect4 xml:id="sockets-bind">
<title><function>bind</function></title>
<para>Ports are like extensions to a phone line: After you
@@ -1094,7 +1086,7 @@ int bind(int s, const struct sockaddr *addr, socklen_t addrlen);
</mediaobject>
</sect4>
- <sect4 id="sockets-listen">
+ <sect4 xml:id="sockets-listen">
<title><function>listen</function></title>
<para>To continue our office phone analogy, after you have
@@ -1119,7 +1111,7 @@ int listen(int s, int backlog);
</sect4>
- <sect4 id="sockets-accept">
+ <sect4 xml:id="sockets-accept">
<title><function>accept</function></title>
<para>After you hear the phone ringing, you accept the call
@@ -1156,7 +1148,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
</sect4>
- <sect4 id="sockets-first-server">
+ <sect4 xml:id="sockets-first-server">
<title>Our First Server</title>
<para>Our first server will be somewhat more complex than
@@ -1512,19 +1504,19 @@ Connection closed by foreign host.
</sect1>
- <sect1 id="sockets-helper-functions">
+ <sect1 xml:id="sockets-helper-functions">
<title>Helper Functions</title>
<para>FreeBSD C library contains many helper functions for sockets
programming. For example, in our sample client we hard coded
- the <hostid role="domainname">time.nist.gov</hostid>
+ the <systemitem class="fqdomainname">time.nist.gov</systemitem>
<acronym>IP</acronym> address. But we do not always know the
<acronym>IP</acronym> address. Even if we do, our software is
more flexible if it allows the user to enter the
<acronym>IP</acronym> address, or even the domain name.
</para>
- <sect2 id="sockets-gethostbyname">
+ <sect2 xml:id="sockets-gethostbyname">
<title><function>gethostbyname</function></title>
<para>While there is no way to pass the domain name directly to
@@ -1606,18 +1598,15 @@ int main(int argc, char *argv[]) {
address, it works both ways) on the command line, and the
program will try to connect to its
<emphasis>daytime</emphasis> server. Otherwise, it will still
- default to <hostid
- role="domainname">time.nist.gov</hostid>. However, even in
+ default to <systemitem class="fqdomainname">time.nist.gov</systemitem>. However, even in
this case we will use <function>gethostbyname</function>
- rather than hard coding <hostid
- role="ipaddr">192.43.244.18</hostid>. That way, even if its
+ rather than hard coding <systemitem class="ipaddress">192.43.244.18</systemitem>. That way, even if its
<acronym>IP</acronym> address changes in the future, we will
still find it.</para>
<para>Since it takes virtually no time to get the time from your
local server, you could run <application>daytime</application>
- twice in a row: First to get the time from <hostid
- role="domainname">time.nist.gov</hostid>, the second time from
+ twice in a row: First to get the time from <systemitem class="fqdomainname">time.nist.gov</systemitem>, the second time from
your own system. You can then compare the results and see how
exact your system clock is:</para>
@@ -1633,7 +1622,7 @@ int main(int argc, char *argv[]) {
</sect2>
- <sect2 id="sockets-getservbyname">
+ <sect2 xml:id="sockets-getservbyname">
<title><function>getservbyname</function></title>
<para>Sometimes you may not be sure what port a certain service
@@ -1678,7 +1667,7 @@ struct servent * getservbyname(const char *name, const char *proto);
</sect1>
- <sect1 id="sockets-concurrent-servers">
+ <sect1 xml:id="sockets-concurrent-servers">
<title>Concurrent Servers</title>
<para>Unlike a sequential server, a <emphasis>concurrent