📄 combine.shar
字号:
chmod 0664 'page02.pre' ||
$echo 'restore of' 'page02.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 'page02.pre:' 'MD5 check failed'
6b27ef52d53a13d2d9e5a5ad16e9be4d page02.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pre'`"
test 416 -eq "$shar_count" ||
$echo 'page02.pre:' 'original size' '416,' 'current size' "$shar_count!"
fi
fi
# ============= page03.pre ==============
if test -f 'page03.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page03.pre' '(file already exists)'
else
$echo 'x -' extracting 'page03.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page03.pre' &&
X
<P>In <A HREF="directed_client.cpp">directed_client.cpp</A> we create a
client that knows how to send a datagram to a server on a known host.
This is a good thing if you know where the server lives and want to have
a conversation. The Unix <I>talk</I> utilitiy, for instance,
could be written this way.
X
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page03.pre' &&
chmod 0664 'page03.pre' ||
$echo 'restore of' 'page03.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 'page03.pre:' 'MD5 check failed'
aa0724ca0a09f5b5e6c7e3f355646111 page03.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pre'`"
test 345 -eq "$shar_count" ||
$echo 'page03.pre:' 'original size' '345,' 'current size' "$shar_count!"
fi
fi
# ============= page04.pre ==============
if test -f 'page04.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page04.pre' '(file already exists)'
else
$echo 'x -' extracting 'page04.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page04.pre' &&
In <A HREF="broadcast_client.cpp">broadcast_client.cpp</A> we
find out how to send a single datagram to every host on our (sub)network.
I have to say <I>(sub)network</I> because broadcast datagrams typically
are not passed through routers. So, if your network admin has divided
up your network into subnets, your broadcasts will likey stay on the
subnet you're a part of.
X
<P>I've only commented the parts that are different from the directed_client.
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page04.pre' &&
chmod 0664 'page04.pre' ||
$echo 'restore of' 'page04.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 'page04.pre:' 'MD5 check failed'
8811bded669a7a7be85a4878d5076190 page04.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pre'`"
test 481 -eq "$shar_count" ||
$echo 'page04.pre:' 'original size' '481,' 'current size' "$shar_count!"
fi
fi
# ============= page05.pre ==============
if test -f 'page05.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page05.pre' '(file already exists)'
else
$echo 'x -' extracting 'page05.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page05.pre' &&
<BR>That's it for this tutorial. In the next one we'll add some intelligence
to the data put into the datagrams. By doing so, we'll be able to
classify our clients and servers into groups. By combining the data
content and the server's port we can get fairly fine-grained control over
who talks to who.
X
<P>For you convenience:
<UL>
<LI>
<A HREF="server.cpp">server.cpp</A></LI>
X
<LI>
<A HREF="directed_client.cpp">directed_client.cpp</A></LI>
X
<LI>
<A HREF="broadcast_client.cpp">broadcast_client.cpp</A></LI>
X
<LI>
<A HREF="Makefile">Makefile</A></LI>
</UL>
SHAR_EOF
$shar_touch -am 03191459100 'page05.pre' &&
chmod 0664 'page05.pre' ||
$echo 'restore of' 'page05.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 'page05.pre:' 'MD5 check failed'
b05fdac8c7eb81813c74eb99525cf601 page05.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pre'`"
test 578 -eq "$shar_count" ||
$echo 'page05.pre:' 'original size' '578,' 'current size' "$shar_count!"
fi
fi
# ============= page02.pst ==============
if test -f 'page02.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page02.pst' '(file already exists)'
else
$echo 'x -' extracting 'page02.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page02.pst' &&
<HR WIDTH="100%">
X
<P>And that's really all there is to it. Obviously there is some
room for improvement. The most blatant is the somewhat small buffer
size for receiving the datagram. I've never been able to get a solid
answer on datagram sizes. The theoretical limit is just under 64k
but you have to deal with fragmentation. Some readings indicate that
8k is a reasonable size, others go much smaller. My general rule
of thumb is to keep datagrams relatively small (eg -- under 8k or so) and
test a lot. If you find that your routers are fragmenting your larger
datagrams, back off to something smaller. Of course, if you must
send 100k and can only do so 1k at a time, you'll have to worry about retransmissions
& reordering. At that point, you might consider going to TCP.
Remember: datagrams are unreliable! Don't try to make 'em do
something they werent' designed for!
SHAR_EOF
$shar_touch -am 03191459100 'page02.pst' &&
chmod 0664 'page02.pst' ||
$echo 'restore of' 'page02.pst' '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 'page02.pst:' 'MD5 check failed'
3cb7da5f75a40616f6cc498a731f4a16 page02.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pst'`"
test 952 -eq "$shar_count" ||
$echo 'page02.pst:' 'original size' '952,' 'current size' "$shar_count!"
fi
fi
# ============= page03.pst ==============
if test -f 'page03.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page03.pst' '(file already exists)'
else
$echo 'x -' extracting 'page03.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page03.pst' &&
<HR WIDTH="100%">
X
<P>That's all neat and good but the point of what we're doing here is not
to talk to a server we know about but to discover servers we don't know
about. Now, you could send a directed datagram to every possible
host address on your network but that's not a very nice thing to do.
On the next page, we'll find out the right approach...
X
SHAR_EOF
$shar_touch -am 03191459100 'page03.pst' &&
chmod 0664 'page03.pst' ||
$echo 'restore of' 'page03.pst' '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 'page03.pst:' 'MD5 check failed'
0fcbc10be47175a0d42590fb4adab43b page03.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pst'`"
test 367 -eq "$shar_count" ||
$echo 'page03.pst:' 'original size' '367,' 'current size' "$shar_count!"
fi
fi
# ============= page04.pst ==============
if test -f 'page04.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page04.pst' '(file already exists)'
else
$echo 'x -' extracting 'page04.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page04.pst' &&
<HR WIDTH="100%">
X
<P> About that subnet thing:
<BLOCKQUOTE>If you run this client on a host that has multiple network
interfaces, the broadcast will go to all of those (sub)networks.
What do you do, though, if you need to get past a router? My advice
is to write a server that will run on hosts on both sides of your router.
When a server on one side of the router receives a broadcast, it would
send a directed datagram to it's counterpart on the other side of the router.
The counterpart would then re-broadcast the original datagram on that sub-net.
Cheap, simple and effective.</BLOCKQUOTE>
One final word of warning:
<BLOCKQUOTE>When creating your broadcast datagrams you may see something
like this: <I>ACE_SOCK_Dgram_Bcast::mk_broadcast: Broadcast is not
enable for this interface.: Unknown error</I>. There are some interfaces
(ppp, slip) that don't support broadcast datagrams. That's what you're
seeing here.</BLOCKQUOTE>
Ok, one more warning:
<blockquote>If you happen to have multiple servers running on your
network when you invoke this client, the response could come from any
one of them.
</blockquote>
X
SHAR_EOF
$shar_touch -am 03191459100 'page04.pst' &&
chmod 0664 'page04.pst' ||
$echo 'restore of' 'page04.pst' '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 'page04.pst:' 'MD5 check failed'
2e01fc6b6638dfa77ed629c0e3e77e21 page04.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pst'`"
test 1173 -eq "$shar_count" ||
$echo 'page04.pst:' 'original size' '1173,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh32494
exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -