home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / Sockets / Source / SOCKC.CPP next >
C/C++ Source or Header  |  1996-08-12  |  3KB  |  122 lines

  1. // OCL - OS/2 Class Library (Samples)
  2. // (c) Cubus 1996
  3. // (c) 1982, 1985, 1986 Regents of the University of California.
  4. // (c) Raoul Gema 1996
  5. // All Rights Reserved
  6. // SOCKC.CPP
  7.  
  8. /*
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  15.  *    endorse or promote products derived from this software
  16.  *    without specific prior written permission.
  17.  * 3. See OCL.INF for a detailed copyright notice.
  18.  *
  19.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  20.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29.  * SUCH DAMAGE.
  30.  */
  31.  
  32. // $Header: W:/Projects/OCL/Samples/Sockets/Source/rcs/SOCKC.CPP 1.50 1996/08/11 23:48:53 B.STEIN Release $
  33.  
  34.  
  35. #include <ocl.hpp>
  36. #include <OIP_Client.hpp>
  37. #include <OMessage.hpp>
  38.  
  39. #define LOGO    "CT.NET++ Mini-Client"
  40.  
  41.  
  42. void usage()
  43. {
  44.  cout <<   "Usage: SOCKC hostname port kommando [text]" << endl 
  45.       << "Command: '='       - show text"               << endl
  46.       << "         '+' text  - add text"                << endl
  47.       << "         '?' text  - search in text"          << endl;
  48.  _exit(1);
  49. }
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53.  OIP_Client  client;
  54.  int         ok;
  55.  
  56.  cout << LOGO
  57.       << endl
  58.       << OIP::Version().getText()
  59.       << endl;
  60.  
  61.  
  62.  if (argc < 4)
  63.    usage();
  64.  
  65.  char command = argv[3][0];
  66.  char* pcommandtext = "";
  67.  
  68.  switch (command)
  69.   {
  70.    case '=':
  71.      break;
  72.    case '+':
  73.    case '?':
  74.     {
  75.      if (argc > 4) {
  76.        pcommandtext = argv[4];
  77.        break; }
  78.     }
  79.    default:
  80.      usage();
  81.   }
  82.  
  83.  try
  84.   {
  85.    OString  data(CCHMAXPATH);
  86.  
  87.    client.init();
  88.    client.connect(argv[1], (USHORT)atoi(argv[2])).connectMsg();
  89.  
  90.    client.recv(data, CCHMAXPATH);
  91.    cout << "Received: "
  92.         << data.getText()
  93.         << endl; 
  94.    sprintf(data, "%c %s", command, pcommandtext);
  95.    client.send(data.getText(), data.length() + 1);
  96.    cout << "Sent    : "
  97.         << data.getText()
  98.         << endl;
  99.    client.recv(data, CCHMAXPATH);
  100.    cout << "Received: "
  101.         << data.getText()
  102.         << endl; 
  103.    ok = 0;
  104.   }
  105.  
  106.  catch (OException& e)
  107.   {
  108.    e.viewError(); 
  109.    ok = -1;
  110.   }
  111.  
  112.  catch (...)
  113.   {
  114.    printf(OIP::error(9));
  115.    ok = -1;
  116.   }
  117.  
  118.  return ok;
  119. }
  120.  
  121. // end of source
  122.