home *** CD-ROM | disk | FTP | other *** search
- /*
- * Xceed Winsock Library Sample: Chat connectionless
- * Copyright (c) 2000 Xceed Software Inc.
- *
- * [ Main.cpp : Entry point of this console application ]
- *
- * This is a minimal implementation of an HTTP server. It
- * only handles the "GET" HTTP command. When a "GET" command
- * is received from a connected client, the server will send
- * the requested file to the client. This is enough functionality
- * to display a web site with bitmaps and regular HTML files.
- *
- * In particular, it demonstrate:
- * - How to create and use a listening socket to handle
- * incoming connections.
- * - How to use string and file transfer interfaces.
- * - Using "#import" with the Xceed Winsock Library.
- * - Using ATL to help implement event interfaces.
- *
- * This file is part of the Xceed Winsock Library Samples.
- * The source code in this file is only intended as a supplement
- * to Xceed Winsock Library's documentation, and is provided "as is",
- * without warranty of any kind, either expressed or implied.
- *
- */
-
- #include "stdafx.h"
- #include <conio.h>
- #include "HttpServer.h"
-
- int main(int argc, char* argv[])
- {
- // Initialize this thread for COM in MTA
- CoInitializeEx( NULL, COINIT_MULTITHREADED );
-
- try
- {
- HRESULT hr;
-
- // Create our server application
- CComObject< CHttpServer >* pxServer;
- hr = CComObject< CHttpServer >::CreateInstance( &pxServer );
-
- if( FAILED( hr ) ) _com_issue_error( hr );
-
- // We must reference this new object, since we use it.
- CComPtr< IUnknown > punkRef;
- hr = pxServer->QueryInterface( &punkRef );
-
- if( FAILED( hr ) ) _com_issue_error( hr );
-
- // We start the server
- hr = pxServer->Start();
-
- if( FAILED( hr ) ) _com_issue_error( hr );
-
- do
- {
- printf( "Press the 'Q' key to quit\n" );
-
- char cHit = getch();
-
- if( cHit == 'q' || cHit == 'Q' )
- break;
-
- } while( true );
-
- // We stop the server. The final Release will free our server.
- hr = pxServer->Stop();
-
- if( FAILED( hr ) ) _com_issue_error( hr );
- }
- catch( const _com_error& xErr )
- {
- printf( "\nERROR %08x: %s\n", xErr.Error(), xErr.ErrorMessage() );
- }
- catch ( ... )
- {
- printf( "\nUNKNOWN ERROR\n" );
- }
-
- CoUninitialize();
- return 0;
- }
-