Using Streaming<ToolKit> with Pipes


A device adapter is provided for the os_pipe class so it can be used with Streaming<ToolKit>. For convenience, an automatic conversion operator allows you to supply an os_pipe instance whenever an os_adapter is expected. Refer to
Streaming<ToolKit> Universal Streaming Service for more information about binary streams. Refer to Streaming<ToolKit> Text Streams for more information about text streams.

The following examples show how to use text streams with a pipe connection to transmit strings between client and server processes.

Example <ospace/pipe/examples/tstream2s.cpp>
// The server process.

#include <iostream>
#include <ospace/pipe.h>
#include <ospace/stream.h>

void
main()
  {
  os_pipe_toolkit init_pipe;
  os_streaming_toolkit init_streaming;

  cout << "Server started." << endl;
  os_pipe_connection_server server( "textpipe" );
  os_pipe pipe;
  server.accept( pipe );

  cout << "Server accepted connection" << endl;
  os_otstream stream( pipe );
  char* txt = "This is a line of text.";
  int num = 42;

  cout << "Writing: " << txt << endl << num << endl;
  stream << txt << endl << num << endl; // Write to the text stream.
  }

Server started.
Server accepted connection
Writing: This is a line of text.
42
Example <ospace/pipe/examples/tstream2c.cpp>
// The client process.

#include <iostream>
#include <ospace/pipe.h>
#include <ospace/stream.h>

void
main()
  {
  os_pipe_toolkit init_pipe;
  os_streaming_toolkit init_streaming;

  cout << "Client started." << endl;
  os_pipe pipe( "textpipe" );
  os_itstream stream( pipe ); // Create a text stream on the pipe.
  cout << "Client connected." << endl;

  // Read from the text stream.
  char buffer[ 32 ];
  int num = -1;
  stream.getline( buffer, sizeof( buffer ) );
  stream >> num;

  cout << "Client read: " << buffer << endl << num << endl;
  }

Client started.
Client connected.
Client read: This is a line of text.
42

The next two examples show how to use an os_bstream with a pipe. The server process uses the stream to send time objects to the client.

Example <ospace/pipe/examples/bstream3s.cpp>
// The server process.

#include <iostream>
#include <ospace/pipe.h>
#include <ospace/stream.h>
#include <ospace/time.h>
#include <ospace/uss/time.h>

void
main()
  {
  os_pipe_toolkit init_pipe;
  os_time_toolkit init_time;
  os_streaming_toolkit init_streaming;

  cout << "Server started." << endl;
  os_pipe_connection_server server( "usspipe" );
  os_pipe pipe;
  server.accept( pipe );
  cout << "Server accepted connection" << endl;

  os_bstream stream( pipe );
  os_time_and_date now = os_time_and_date::now();
  cout << "Server writes: " << now << endl;
  stream << now;
  }

Server started.
Server accepted connection
Server writes: 10/02/96 11:07:30:363482
Example <ospace/pipe/examples/bstream3c.cpp>
// The client process.

#include <iostream>
#include <ospace/pipe.h>
#include <ospace/stream.h>
#include <ospace/time.h>
#include <ospace/uss/time.h>

void
main()
  {
  os_pipe_toolkit init_pipe;
  os_time_toolkit init_time;
  os_streaming_toolkit init_streaming;

  cout << "Client started." << endl;
  os_pipe pipe( "usspipe" );
  cout << "Client connected." << endl;

  os_bstream stream( pipe );
  os_time_and_date now;
  stream >> now;
  cout << "Client read: " << now << endl;
  }

Client started.
Client connected.
Client read: 10/02/96 11:07:30:363482


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.