📄 combine.shar
字号:
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2000-03-19 15:00 EST by <jcej@chiroptera.tragus.org>.
# Source directory was `/home/jcej/projects/ACE_wrappers/docs/tutorials/008'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 515 -rw-rw-r-- hdr
# 59 -rw-rw-r-- bodies
# 2767 -rw-rw-r-- page01.pre
# 416 -rw-rw-r-- page02.pre
# 345 -rw-rw-r-- page03.pre
# 481 -rw-rw-r-- page04.pre
# 578 -rw-rw-r-- page05.pre
# 952 -rw-rw-r-- page02.pst
# 367 -rw-rw-r-- page03.pst
# 1173 -rw-rw-r-- page04.pst
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh32494; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= hdr ==============
if test -f 'hdr' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'hdr' '(file already exists)'
else
$echo 'x -' extracting 'hdr' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'hdr' &&
<HTML>
<HEAD>
X <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
X <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i486) [Netscape]">
X <META NAME="Author" CONTENT="James CE Johnson">
X <TITLE>ACE Tutorial 008</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">
X
<CENTER><B><FONT SIZE=+2>ACE Tutorial 008</FONT></B></CENTER>
X
<CENTER><B><FONT SIZE=+2>Sending and receiving datagrams</FONT></B></CENTER>
X
X
<P>
<HR WIDTH="100%">
X
SHAR_EOF
$shar_touch -am 03191459100 'hdr' &&
chmod 0664 'hdr' ||
$echo 'restore of' 'hdr' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'hdr:' 'MD5 check failed'
e74ecd3335da844c263f961a8ba5f867 hdr
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`"
test 515 -eq "$shar_count" ||
$echo 'hdr:' 'original size' '515,' 'current size' "$shar_count!"
fi
fi
# ============= bodies ==============
if test -f 'bodies' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'bodies' '(file already exists)'
else
$echo 'x -' extracting 'bodies' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'bodies' &&
PAGE=2
server.cpp
directed_client.cpp
broadcast_client.cpp
SHAR_EOF
$shar_touch -am 0121153799 'bodies' &&
chmod 0664 'bodies' ||
$echo 'restore of' 'bodies' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'bodies:' 'MD5 check failed'
707d1735ca25694e2b5fddc1f6e7e124 bodies
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`"
test 59 -eq "$shar_count" ||
$echo 'bodies:' 'original size' '59,' 'current size' "$shar_count!"
fi
fi
# ============= page01.pre ==============
if test -f 'page01.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page01.pre' '(file already exists)'
else
$echo 'x -' extracting 'page01.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page01.pre' &&
<P>In a lot of IPC programming, the clients know where the servers
are. A mail client, for instance, has a configuration file that says
where the mail host is. Your web browser has a "location" field that
you type into to give it a destination.
X
<P>What if you have written a server application and then you execute it
on several systems in your network? All of the instances are probably
more or less equal to the client's point of view, so you don't want to
"configure" the clients to a single server each. Likewise, you
want the ability to add and remove servers at any time so you can't just
give the clients a list to choose from.
X
<P>So... how do the clients know where the servers are?
X
<P>Let 'em ask!
X
<P>Datagrams are great for this. You can toss a datagram out onto
the network and any servers listening at the correct port will* hear it.
Like ACE_SOCK_Stream that we've seen before, you can get the peer address
from a datagram. With that, the server can send a response
back to the client. The client, in turn, can pull the peer address
out and know exactly where the server lives.
X
<P>In this tutorial we'll develop three applications: a server listening
for datagrams, a client that can send to a known host and a client that
can send to the entire (sub)network. In the next tutorial, we'll
expand on this to make the server a bit more prudish.
<P>
Kirthika's abstract:
<UL>
Here, we play with datagram sockets and use it for server discovery by
the client. Datagrams are used by UDP, which is an unreliable and
connectionless protocol. Datagrams packets are generally very small in
size and aren't designed to be used to handle serious communication
between the server and the client.
<P>
The server waits for datagrams to arrive at a fixed port.
The client either sends to a datagram to the server at a known host,
which is not really the case generally, as the client needs to discover
the server and so it needs to broadcast its datagram request in its
subnet. Then, all servers listening at that interface receive it. The
appropriate server will then handle the request. Remember that
no solid connection is made. On the recv() itself the server obtains the
address of the remote client and then communicates with it.
<P>
Thus, we get a fair glimpse of using another means of communication via
datagrams.
</UL>
<P><FONT SIZE=-1>* Actually, the servers <I>might</I> hear the datagram.
Datagrams are rather unreliable. (Sort of like some operating systems
I know.) Still, if the network traffic isn't too bad, they generally
get through. Your clients can always send out more queries if there
aren't any responses in a timely fashion.</FONT>
X
SHAR_EOF
$shar_touch -am 03191459100 'page01.pre' &&
chmod 0664 'page01.pre' ||
$echo 'restore of' 'page01.pre' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page01.pre:' 'MD5 check failed'
0773df98f89130f72767715ed27516b6 page01.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`"
test 2767 -eq "$shar_count" ||
$echo 'page01.pre:' 'original size' '2767,' 'current size' "$shar_count!"
fi
fi
# ============= page02.pre ==============
if test -f 'page02.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page02.pre' '(file already exists)'
else
$echo 'x -' extracting 'page02.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page02.pre' &&
X
<P>The first thing we want to look at is <A HREF="server.cpp">server.cpp</A>.
This is a pretty simple application that listens for datagrams at a known
port and sends back a response. In order to implement a true "discovery"
mechanism, the server will have to be a little bit more picky about who
it responds to. We'll tackle that issue in the next tutorial though...
X
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page02.pre' &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -