home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / samples / sample16 / client.cpp next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  1.5 KB  |  48 lines

  1. #include <fstream.h>
  2. #include <xheaders.h>
  3. #include XSocket_i
  4.  
  5. void main( int argc, char** argv )
  6. {
  7.         if( argc < 3 )
  8.         {
  9.                 cout << "Usage: client <hostname> <port number>" << endl;
  10.                 cout << "e.g.: client localhost 1000" << endl;
  11.         }
  12.         else
  13.         {
  14.                 XClientSocket* pClientSocket;
  15.  
  16.                 try
  17.                 {
  18.                         XString message;
  19.                         message.GetBuffer( 40 );
  20.  
  21.                         cout << "Connecting to server...";
  22.                         pClientSocket = new XClientSocket();
  23.                         pClientSocket->Open();
  24.                         pClientSocket->GetHostByName( argv[1] );
  25.                         pClientSocket->SetInAddress();
  26.                         pClientSocket->SetInPort( atoi( argv[2] ) );
  27.                         pClientSocket->Connect();
  28.                         cout << "done." << endl;
  29.  
  30.                         cout << "Sending data...";
  31.                         XString s = "This is a test!";
  32.                         pClientSocket->XIO::Write( s );
  33.                         cout << "done." << endl;
  34.  
  35.                         cout << "Received data: ";
  36.                         pClientSocket->Read( message, 39 );
  37.                         cout << message << endl;
  38.  
  39.                         delete pClientSocket;
  40.                 }
  41.                 catch( XException* x )
  42.                 {
  43.                         x->PrintError();
  44.                 }
  45.         }
  46. }
  47.  
  48.