diff options
author | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-09-23 19:31:01 +0000 |
---|---|---|
committer | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-09-23 19:31:01 +0000 |
commit | 08d2cf8ae623f5aa87ad12ff30ad4ea9e40c8956 (patch) | |
tree | 7cadcc4a888a92984e1d9c9f98ae22367e360838 /docs/tutorials/003 | |
parent | caff940a39e93bc503c3a18ef4daf9aa0a85172b (diff) | |
download | ATCD-pre_avsvc_split.tar.gz |
This commit was manufactured by cvs2svn to create tagpre_avsvc_split
'pre_avsvc_split'.
Diffstat (limited to 'docs/tutorials/003')
-rw-r--r-- | docs/tutorials/003/003.dsp | 100 | ||||
-rw-r--r-- | docs/tutorials/003/00SetEnv | 2 | ||||
-rw-r--r-- | docs/tutorials/003/Makefile | 51 | ||||
-rw-r--r-- | docs/tutorials/003/client.cpp | 98 | ||||
-rw-r--r-- | docs/tutorials/003/combine.shar | 217 | ||||
-rw-r--r-- | docs/tutorials/003/page01.html | 159 |
6 files changed, 0 insertions, 627 deletions
diff --git a/docs/tutorials/003/003.dsp b/docs/tutorials/003/003.dsp deleted file mode 100644 index c4a5a21faa4..00000000000 --- a/docs/tutorials/003/003.dsp +++ /dev/null @@ -1,100 +0,0 @@ -# Microsoft Developer Studio Project File - Name="003" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=003 - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "003.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "003.mak" CFG="003 - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "003 - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "003 - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "003 - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ace.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\ace"
-
-!ELSEIF "$(CFG)" == "003 - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /GX /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 aced.lib /nologo /subsystem:console /debug /machine:I386 /out:"client.exe" /pdbtype:sept /libpath:"..\..\..\ace"
-
-!ENDIF
-
-# Begin Target
-
-# Name "003 - Win32 Release"
-# Name "003 - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\client.cpp
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/docs/tutorials/003/00SetEnv b/docs/tutorials/003/00SetEnv deleted file mode 100644 index eca78e10c85..00000000000 --- a/docs/tutorials/003/00SetEnv +++ /dev/null @@ -1,2 +0,0 @@ -export ACE_ROOT=/local/src/ACE/ACE_wrappers -export LD_LIBRARY_PATH=$ACE_ROOT/ace:$LD_LIBRARY_PATH diff --git a/docs/tutorials/003/Makefile b/docs/tutorials/003/Makefile deleted file mode 100644 index 874926a64f1..00000000000 --- a/docs/tutorials/003/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -#---------------------------------------------------------------------------- -# $Id$ -# -# Makefile for client logging applications -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = client - -LSRC = $(addsuffix .cpp,$(BIN)) - -VLDLIBS = $(LDLIBS:%=%$(VAR)) - -BUILD = $(VBIN) - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU -include $(ACE_ROOT)/include/makeinclude/rules.local.GNU - -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -HTML : # - [ -f hdr ] || $(MAKE) UNSHAR - perl ../combine *.pre ; chmod +r *.html - -SHAR : # - [ ! -f combine.shar ] || exit 1 - shar -T hdr bodies *.pre *.pst > combine.shar && $(RM) hdr bodies *.pre *.pst - -UNSHAR : # - sh combine.shar - -CLEAN : realclean - $(RM) hdr bodies *.pre *.pst .depend - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- - diff --git a/docs/tutorials/003/client.cpp b/docs/tutorials/003/client.cpp deleted file mode 100644 index 1c93769e7bd..00000000000 --- a/docs/tutorials/003/client.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// $Id$ - -/* To establish a socket connection to a server, we'll need an - ACE_SOCK_Connector. */ -#include "ace/SOCK_Connector.h" - -/* Unlike the previous two tutorials, we're going to allow the user to - provide command line options this time. Still, we need defaults in - case that isn't done. */ -static u_short SERVER_PORT = ACE_DEFAULT_SERVER_PORT; -static const char *const SERVER_HOST = ACE_DEFAULT_SERVER_HOST; -static const int MAX_ITERATIONS = 4; - -int -main (int argc, char *argv[]) -{ - /* Accept the users's choice of hosts or use the default. Then do - the same for the TCP/IP port at which the server is listening as - well as the number of iterations to perform. */ - const char *server_host = argc > 1 ? argv[1] : SERVER_HOST; - u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : SERVER_PORT; - int max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : MAX_ITERATIONS; - - /* Build ourselves a Stream socket. This is a connected socket that - provides reliable end-to-end communications. We will use the - server object to send data to the server we connect to. */ - ACE_SOCK_Stream server; - - /* And we need a connector object to establish that connection. The - ACE_SOCK_Connector object provides all of the tools we need to - establish a connection once we know the server's network - address... */ - ACE_SOCK_Connector connector; - - /* Which we create with an ACE_INET_Addr object. This object is - given the TCP/IP port and hostname of the server we want to - connect to. */ - ACE_INET_Addr addr (server_port, - server_host); - - /* So, we feed the Addr object and the Stream object to the - connector's connect() member function. Given this information, it - will establish the network connection to the server and attach - that connection to the server object. */ - if (connector.connect (server, addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "open"), - -1); - - /* Just for grins, we'll send the server several messages. */ - for (int i = 0; i < max_iterations; i++) - { - char buf[BUFSIZ]; - - /* Create our message with the message number */ - ACE_OS::sprintf (buf, - "message = %d\n", - i + 1); - /* Send the message to the server. We use the server object's - send_n() function to send all of the data at once. There is - also a send() function but it may not send all of the - data. That is due to network buffer availability and such. If - the send() doesn't send all of the data, it is up to you to - program things such that it will keep trying until all of the - data is sent or simply give up. The send_n() function already - does the "keep trying" option for us, so we use it. - - Like the send() method used in the servers we've seen, there - are two additional parameters you can use on the send() and - send_n() method calls. The timeout parameter limits the - amount of time the system will attempt to send the data to the - peer. The flags parameter is passed directly to the OS send() - system call. See send(2) for the valid flags values. */ - if (server.send_n (buf, - ACE_OS::strlen (buf)) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "send"), - -1); - else - /* Pause for a second. */ - ACE_OS::sleep (1); - } - - /* Close the connection to the server. The servers we've created so - far all are based on the ACE_Reactor. When we close(), the - server's reactor will see activity for the registered event - handler and invoke handle_input(). That, in turn, will try to - read from the socket but get back zero bytes. At that point, the - server will know that we've closed from our side. */ - if (server.close () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "close"), - -1); - return 0; -} diff --git a/docs/tutorials/003/combine.shar b/docs/tutorials/003/combine.shar deleted file mode 100644 index 67aebd9b3fd..00000000000 --- a/docs/tutorials/003/combine.shar +++ /dev/null @@ -1,217 +0,0 @@ -#!/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 1999-09-21 22:49 EDT by <jcej@chiroptera.tragus.org>. -# Source directory was `/home/jcej/projects/ACE_wrappers/docs/tutorials/003'. -# -# Existing files will *not* be overwritten unless `-c' is specified. -# -# This shar contains: -# length mode name -# ------ ---------- ------------------------------------------ -# 607 -rw-rw-r-- hdr -# 18 -rw-rw-r-- bodies -# 1155 -rw-rw-r-- page01.pre -# 447 -rw-rw-r-- page01.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 _sh04727; 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 <META NAME="Description" CONTENT="A first step towards using ACE productively"> -X <TITLE>ACE Tutorial 003</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> -X -<CENTER><B><FONT SIZE=+2>ACE Tutorial 003</FONT></B></CENTER> -X -<CENTER><B><FONT SIZE=+2>Creating a Simple Client</FONT></B></CENTER> -X -X -<P> -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0117142499 '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' -91fd92d4f4daf6d2c38ccda9486b10ee hdr -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`" - test 607 -eq "$shar_count" || - $echo 'hdr:' 'original size' '607,' '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=1 -client.cpp -SHAR_EOF - $shar_touch -am 0117142499 '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' -d02fcd98e57e40350f82497be4ac0e0c bodies -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`" - test 18 -eq "$shar_count" || - $echo 'bodies:' 'original size' '18,' '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' && -X -<P>Now that we've seen how to create servers, let's spend just a moment -making a client. Since this is so easy, I'm going to do all of it in this -one page. -X -<P> -Kirthika says, "Here's an one paragraph abstract for a one page client app:" -X -<UL> -X The server is an Stream object of ACE_SOCK_Stream type. The -X ACE_Sock_Connector does the job of actively making a connection with the -X listening server. It does so using the server_host_address and port -X number which are stored in the ACE_INET_Addr object.Once the -X connection has been established, the client begins its interaction -X with the server and bombards it with messages. -X Note: send_n() call is used since this call sees to the issues of -X network buffering and reliably gets the data across to the server. -X Also, a timeout value is set to provide fault tolerance if the server -X ever dies before the transaction is completed. The server calls a -X close() method -X once it reads in zero bytes during the Event_Handler::handle_input() -X call. This -X proves that the client has severed its connection. The server then -X shuts down. -</UL> -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0117142499 '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' -c35cf15b292804d248dee8e4cc6feec5 page01.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`" - test 1155 -eq "$shar_count" || - $echo 'page01.pre:' 'original size' '1155,' 'current size' "$shar_count!" - fi -fi -# ============= page01.pst ============== -if test -f 'page01.pst' && test "$first_param" != -c; then - $echo 'x -' SKIPPING 'page01.pst' '(file already exists)' -else - $echo 'x -' extracting 'page01.pst' '(text)' - sed 's/^X//' << 'SHAR_EOF' > 'page01.pst' && -<HR WIDTH="100%"> -X -<P>Ok, so that was pretty easy. What would be even easier would be to wrap -all of the connection mess up in an object and overload a couple of basic -operators to make things less network-centric. Perhaps we'll see that in -another tutorial. -X -<P>If you want to compile it yourself, here's the <A HREF="client.cpp">source</A>, -the <A HREF="Makefile">Makefile</A>, -and <A HREF="00SetEnv">Environment -settings</A>. -X -<P> -SHAR_EOF - $shar_touch -am 0117142499 'page01.pst' && - chmod 0664 'page01.pst' || - $echo 'restore of' 'page01.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 'page01.pst:' 'MD5 check failed' -9c3589ed1d86da267d589599f914141e page01.pst -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pst'`" - test 447 -eq "$shar_count" || - $echo 'page01.pst:' 'original size' '447,' 'current size' "$shar_count!" - fi -fi -rm -fr _sh04727 -exit 0 diff --git a/docs/tutorials/003/page01.html b/docs/tutorials/003/page01.html deleted file mode 100644 index fcf34fa66db..00000000000 --- a/docs/tutorials/003/page01.html +++ /dev/null @@ -1,159 +0,0 @@ -<!-- $Id$ --> -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i486) [Netscape]"> - <META NAME="Author" CONTENT="James CE Johnson"> - <META NAME="Description" CONTENT="A first step towards using ACE productively"> - <TITLE>ACE Tutorial 003</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 003</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Creating a Simple Client</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> - -<P>Now that we've seen how to create servers, let's spend just a moment -making a client. Since this is so easy, I'm going to do all of it in this -one page. - -<P> -Kirthika says, "Here's an one paragraph abstract for a one page client app:" - -<UL> - The server is an Stream object of ACE_SOCK_Stream type. The - ACE_Sock_Connector does the job of actively making a connection with the - listening server. It does so using the server_host_address and port - number which are stored in the ACE_INET_Addr object.Once the - connection has been established, the client begins its interaction - with the server and bombards it with messages. - Note: send_n() call is used since this call sees to the issues of - network buffering and reliably gets the data across to the server. - Also, a timeout value is set to provide fault tolerance if the server - ever dies before the transaction is completed. The server calls a - close() method - once it reads in zero bytes during the Event_Handler::handle_input() - call. This - proves that the client has severed its connection. The server then - shuts down. -</UL> -<HR WIDTH="100%"> -<PRE> -<font color=red>// $Id$</font> - -<font color=red>/* To establish a socket connection to a server, we'll need an - ACE_SOCK_Connector. */</font> -<font color=blue>#include</font> "<A HREF="../../../ace/SOCK_Connector.h">ace/SOCK_Connector.h</A>" - -<font color=red>/* Unlike the previous two tutorials, we're going to allow the user to - provide command line options this time. Still, we need defaults in - case that isn't done. */</font> -static u_short SERVER_PORT = ACE_DEFAULT_SERVER_PORT; -static const char *const SERVER_HOST = ACE_DEFAULT_SERVER_HOST; -static const int MAX_ITERATIONS = 4; - -int -main (int argc, char *argv[]) -{ - <font color=red>/* Accept the users's choice of hosts or use the default. Then do - the same for the TCP/IP port at which the server is listening as - well as the number of iterations to perform. */</font> - const char *server_host = argc > 1 ? argv[1] : SERVER_HOST; - u_short server_port = argc > 2 ? <font color=#008888>ACE_OS::atoi</font> (argv[2]) : SERVER_PORT; - int max_iterations = argc > 3 ? <font color=#008888>ACE_OS::atoi</font> (argv[3]) : MAX_ITERATIONS; - - <font color=red>/* Build ourselves a Stream socket. This is a connected socket that - provides reliable end-to-end communications. We will use the - server object to send data to the server we connect to. */</font> - ACE_SOCK_Stream server; - - <font color=red>/* And we need a connector object to establish that connection. The - ACE_SOCK_Connector object provides all of the tools we need to - establish a connection once we know the server's network - address... */</font> - ACE_SOCK_Connector connector; - - <font color=red>/* Which we create with an ACE_INET_Addr object. This object is - given the TCP/IP port and hostname of the server we want to - connect to. */</font> - ACE_INET_Addr addr (server_port, - server_host); - - <font color=red>/* So, we feed the Addr object and the Stream object to the - connector's connect() member function. Given this information, it - will establish the network connection to the server and attach - that connection to the server object. */</font> - if (connector.connect (server, addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "<font color=green>%p\n</font>", - "<font color=green>open</font>"), - -1); - - <font color=red>/* Just for grins, we'll send the server several messages. */</font> - for (int i = 0; i < max_iterations; i++) - { - char buf[BUFSIZ]; - - <font color=red>/* Create our message with the message number */</font> - <font color=#008888>ACE_OS::sprintf</font> (buf, - "<font color=green>message = %d\n</font>", - i + 1); - <font color=red>/* Send the message to the server. We use the server object's - send_n() function to send all of the data at once. There is - also a send() function but it may not send all of the - data. That is due to network buffer availability and such. If - the send() doesn't send all of the data, it is up to you to - program things such that it will keep trying until all of the - data is sent or simply give up. The send_n() function already - does the "<font color=green>keep trying</font>" option for us, so we use it. - - Like the send() method used in the servers we've seen, there - are two additional parameters you can use on the send() and - send_n() method calls. The timeout parameter limits the - amount of time the system will attempt to send the data to the - peer. The flags parameter is passed directly to the OS send() - system call. See send(2) for the valid flags values. */</font> - if (server.send_n (buf, - <font color=#008888>ACE_OS::strlen</font> (buf)) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "<font color=green>%p\n</font>", - "<font color=green>send</font>"), - -1); - else - <font color=red>/* Pause for a second. */</font> - <font color=#008888>ACE_OS::sleep</font> (1); - } - - <font color=red>/* Close the connection to the server. The servers we've created so - far all are based on the ACE_Reactor. When we close(), the - server's reactor will see activity for the registered event - handler and invoke handle_input(). That, in turn, will try to - read from the socket but get back zero bytes. At that point, the - server will know that we've closed from our side. */</font> - if (server.close () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "<font color=green>%p\n</font>", - "<font color=green>close</font>"), - -1); - return 0; -} -</PRE> -<HR WIDTH="100%"> - -<P>Ok, so that was pretty easy. What would be even easier would be to wrap -all of the connection mess up in an object and overload a couple of basic -operators to make things less network-centric. Perhaps we'll see that in -another tutorial. - -<P>If you want to compile it yourself, here's the <A HREF="client.cpp">source</A>, -the <A HREF="Makefile">Makefile</A>, -and <A HREF="00SetEnv">Environment -settings</A>. - -<P> -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] </CENTER> |