home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedWinsock.Cab / F112764_Main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-19  |  2.3 KB  |  85 lines

  1. /*
  2.  * Xceed Winsock Library Sample: Chat connectionless
  3.  * Copyright (c) 2000 Xceed Software Inc.
  4.  *
  5.  * [ Main.cpp : Entry point of this console application ]
  6.  *
  7.  * This is a minimal implementation of an HTTP server. It
  8.  * only handles the "GET" HTTP command. When a "GET" command
  9.  * is received from a connected client, the server will send
  10.  * the requested file to the client. This is enough functionality
  11.  * to display a web site with bitmaps and regular HTML files.
  12.  *
  13.  * In particular, it demonstrate:
  14.  *  - How to create and use a listening socket to handle
  15.  *    incoming connections.
  16.  *  - How to use string and file transfer interfaces.
  17.  *  - Using "#import" with the Xceed Winsock Library.
  18.  *  - Using ATL to help implement event interfaces.
  19.  *
  20.  * This file is part of the Xceed Winsock Library Samples.
  21.  * The source code in this file is only intended as a supplement
  22.  * to Xceed Winsock Library's documentation, and is provided "as is", 
  23.  * without warranty of any kind, either expressed or implied.
  24.  *
  25.  */
  26.  
  27. #include "stdafx.h"
  28. #include <conio.h>
  29. #include "HttpServer.h"
  30.  
  31. int main(int argc, char* argv[])
  32. {
  33.   // Initialize this thread for COM in MTA
  34.   CoInitializeEx( NULL, COINIT_MULTITHREADED );
  35.  
  36.   try
  37.   {
  38.     HRESULT hr;
  39.  
  40.     // Create our server application
  41.     CComObject< CHttpServer >*  pxServer;
  42.     hr = CComObject< CHttpServer >::CreateInstance( &pxServer );
  43.  
  44.     if( FAILED( hr ) ) _com_issue_error( hr );
  45.  
  46.     // We must reference this new object, since we use it.
  47.     CComPtr< IUnknown > punkRef;
  48.     hr = pxServer->QueryInterface( &punkRef );
  49.  
  50.     if( FAILED( hr ) ) _com_issue_error( hr );
  51.  
  52.     // We start the server
  53.     hr = pxServer->Start();
  54.  
  55.     if( FAILED( hr ) ) _com_issue_error( hr );
  56.  
  57.     do
  58.     {
  59.       printf( "Press the 'Q' key to quit\n" );
  60.  
  61.       char cHit = getch();
  62.  
  63.       if( cHit == 'q' || cHit == 'Q' )
  64.         break;
  65.  
  66.     } while( true );
  67.   
  68.     // We stop the server. The final Release will free our server.
  69.     hr = pxServer->Stop();
  70.  
  71.     if( FAILED( hr ) ) _com_issue_error( hr );
  72.   }
  73.   catch( const _com_error& xErr ) 
  74.   {
  75.     printf( "\nERROR %08x: %s\n", xErr.Error(), xErr.ErrorMessage() );
  76.   }
  77.   catch ( ... ) 
  78.   {
  79.     printf( "\nUNKNOWN ERROR\n" );
  80.   }
  81.  
  82.   CoUninitialize();
  83.     return 0;
  84. }
  85.