// ------------------------------- //
// -------- Start of File -------- //
// ------------------------------- //
// ----------------------------------------------------------- // 
// C++ Source Code File Name: client.cpp
// C++ Compiler Used: MSVC40, HP CPP 10.24, egcs-2.90.29 
// Produced By: Doug Gaer   
// File Creation Date: 09/20/1999
// Date Last Modified: 06/21/2000
// Copyright (c) 2000 Douglas M. Gaer
// ----------------------------------------------------------- // 
// ------------- Program Description and Details ------------- // 
// ----------------------------------------------------------- // 
/*
The VBS C++ classes are copyright (c) 2000, by Douglas M. Gaer.
All those who put this code or its derivatives in a commercial
product MUST mention this copyright in their documentation for
users of the products in which this code or its derivative
classes are used. Otherwise, you have the freedom to redistribute
verbatim copies of this source code, adapt it to your specific
needs, or improve the code and release your improvements to the
public provided that the modified files carry prominent notices
stating that you changed the files and the date of any change.

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
CORRECTION.

Simple datagram client demo using the vbSocket class.
*/
// ----------------------------------------------------------- // 
#include <iostream.h>
#include <stdlib.h>
#include "vbsocket.h"

int main(int argc, char **argv)
{
  if(argc != 3) {
    cerr << "Usage: " << argv[0] << " hostname port" << endl;
    return 1;
  }

  unsigned short port = (unsigned short) atoi(argv[2]);

  cout << "Construcing datagram client..." << endl;
  vbSocket client(SOCK_DGRAM, port, argv[1]);
  if(!client) {
    cout << client.SocketExceptionMessage() << endl;
    return 1;
  }

  char *test_block = "The quick brown fox jumps over the lazy dog \
0123456789\n";
  
  // Send a block of data
  cout << "Sending a block " << strlen(test_block) << " bytes long..." << endl;
  int rv = client.SendTo((char *)test_block, strlen(test_block));
  if(rv < 0) {
    cout << client.SocketExceptionMessage() << endl;
    return 1;
  }

  cout << "Sent " << rv << " bytes" << endl;
  cout << "Exiting..." << endl;
  client.Close(); // Close the socket connection
  client.ReleaseSocketLibrary();
  
  return 0;
}
// ----------------------------------------------------------- // 
// ------------------------------- //
// --------- End of File --------- //
// ------------------------------- //