Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / IOStream / client / iostream_client.cpp
blob3d71a72bde5637ecc436ee1b6d54455283e13655
1 #include "ace/SOCK_Connector.h"
2 #include "ace/IOStream.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdlib.h"
5 #include "ace/OS_NS_unistd.h"
7 // This client is a simple example of using the ACE_IOStream and
8 // ACE_Streambuf_T templates to create an object based on ACE_*_Stream
9 // classes, which mimic a C++ iostream.
11 int
12 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
14 #if !defined (ACE_LACKS_ACE_IOSTREAM)
15 const ACE_TCHAR *server_host = argc > 1 ? argv[1] : ACE_DEFAULT_SERVER_HOST;
16 u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT;
18 ACE_IOStream<ACE_SOCK_Stream> server;
19 ACE_SOCK_Connector connector;
20 ACE_INET_Addr addr (server_port,
21 server_host);
23 if (connector.connect (server, addr) == -1)
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "%p\n",
26 "open"),
27 -1);
29 // Buffer up some things to send to the server.
30 server << "1 2.3 testing" << endl;
32 int i;
33 float f;
35 ACE_IOStream_String s1;
36 ACE_IOStream_String s2;
37 server >> s1 >> i >> f >> s2;
39 cerr << "Server said:\n\t";
40 cerr << s1 << " ";
41 cerr << i << " ";
42 cerr << f << " ";
43 cerr << s2 << endl;
45 if (server.close () == -1)
46 ACE_ERROR_RETURN ((LM_ERROR,
47 "%p\n",
48 "close"),
49 -1);
50 #else
51 ACE_UNUSED_ARG (argc);
52 ACE_UNUSED_ARG (argv);
53 ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n"));
54 #endif /* !ACE_LACKS_ACE_IOSTREAM */
55 return 0;