diff options
Diffstat (limited to 'docs/tutorials/004/foo')
-rw-r--r-- | docs/tutorials/004/foo | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/docs/tutorials/004/foo b/docs/tutorials/004/foo deleted file mode 100644 index ed5e75c78da..00000000000 --- a/docs/tutorials/004/foo +++ /dev/null @@ -1,141 +0,0 @@ - -1. #include "ace/SOCK_Connector.h" -2. #include "ace/SString.h" - -3. class Client : private ACE_SOCK_Stream - { - - public: -4. ACE_SOCK_Stream::close; // promote to public - -5. Client(void); -6. Client( const char * server, u_short port ); - -7. int open( const char * server, u_short port ); - -8. inline int initialized(void) { return mInitialized; } -9. inline int error(void) { return mError; } - -10. Client & operator<<( ACE_SString & str ); -11. Client & operator<<( char * str ); -12. Client & operator<<( int n ); - -13. class Error {}; - - protected: - - private: -14. unsigned char mInitialized; -15. unsigned char mError; - }; - -16. Client::Client(void) - { -17. mInitialized = 0; -18. mError = 0; - } - -19. Client::Client( const char * server, u_short port ) - { -20. mInitialized = 0; -21. mError = 0; -22. (void)open(server,port); - } - -23. int Client::open( const char * server, u_short port ) - { -24. ACE_SOCK_Connector connector; -25. ACE_INET_Addr addr (port, server); - -26. if (connector.connect (*this, addr) == -1) - { -27. ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); - } - -28. mInitialized = 1; - -29. return(0); - } - -30. Client & Client::operator<<( ACE_SString & str ) - { -31. if( initialized() ) - { -32. if( error() ) - { -33. throw Error(); - } - -34. char * cp = str.rep(); - -35. mError = 0; - -36. if( this->send_n(cp,strlen(cp)) == -1 ) - { -37. mError = 1; -38. throw Error(); - } - } -39. else - { -40. mError = 2; -41. throw Error(); - } - -42. return *this ; - } - -43. Client & Client::operator<< ( char * str ) - { -44. ACE_SString newStr(str); - -45. *this << newStr; - -46. return *this ; - } - -47. Client & Client::operator<< ( int n ) - { -48. char buf[1024]; -49. sprintf(buf,"(%d)\n",n); -50. ACE_SString newStr(buf); - -51. *this << newStr; - -52. return *this; - } - -53. int main (int argc, char *argv[]) - { -54. const char *server_host = argc > 1 ? argv[1] : ACE_DEFAULT_SERVER_HOST; -55. u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT; -56. int max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : 4; - -57. Client server(server_host,server_port); - -58. if( ! server.initialized() ) - { -59. ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "intialization"), -1); - } - - -60. for (int i = 0; i < max_iterations; i++) - { -61. try - { -62. server << "message = " << i+1; -63. ACE_OS::sleep (1); - } -64. catch ( Client::Error & e ) - { -65. cout << "There was an error sending the data\n"; - } - } - -66. if (server.close () == -1) - { -67. ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), -1); - } - -68. return 0; - } |