Handling requests

Servers generally process in a loop, waiting for incoming requests. To handle a server request, define a loop to:

  1. Call TRequestReceiverStream::Receive.
  2. Stream the request from TRequestReceiverStream.
  3. Formulate a reply.
  4. Stream the reply into TRequestReceiverStream.
  5. Call TRequestReceiverStream::Reply to send the reply back to the client.
NOTE By default, the request-reply interface throws an exception if your code does not stream in the full request from TRequestReceiverStream before streaming the reply out to the TRequestReceiverStream. If you do not want to stream in the full request, call TRequestReceiverStream::FlushRequest before beginning to stream out the reply.

This sequence of operations must always be performed sequentially. TRequestReceiverSTream is not multithread-safe.

This example shows a simple loop that receives requests, processes them, and replies to the client.

      while (TRUE)
      {
          myReceiver.Receive () ;
          theRequest <<= myReceiver ;
          // do the processing or call a function that does it
          theReply =>> myReceiver ;
          myReceiver.Reply () ;
      };

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker