Creating and Monitoring Peer-to-Peer Streams

Use the Peer To Peer Streaming functions to create and monitor peer-to-peer streams.

Creating a Peer-to-Peer Stream

Complete the following steps to create a stream.

  1. Configure the writer and reader. Refer to the hardware API documentation for information about configuring a writer or reader.
  2. Obtain the references to the writer and reader using methods associated with the hardware API.
  3. Set the writer and reader references to the writerEndPointHandle and readerEndpointHandle inputs of the nip2pCreateAndLinkStream function. This function associates the writer and reader with the stream. After this function runs, the stream is in a Disabled or Enabled state depending on the value of enableStream.
  4. (Optional) Use the nip2pEnableStream function to enable the stream. You do not need to use this function if you set the enableStream input of the nip2pCreateAndLinkStream function to 1.
  5. Stop the data transmission and disable the stream using the nip2pDisableStream function or the nip2pFlushAndDisableStream function.
  6. Use the nip2pDestroyStream function to unlink and destroy the stream.

Monitoring the Status of a Peer-to-Peer Stream

In C, you can monitor peer-to-peer stream events such as overflow, underflow, and stream state by either waiting for a specific event to occur or by polling the status attribute.

To wait for a specific event, call the nip2pWaitForStreamEvent function. This function waits for a specific event to occur, or for the timeout to expire, before returning.

To poll to see if a specific event has occurred, call the nip2pGetAttribute function. The attributes that correspond to the stream state are nip2p_kStreamAttributeStreamState, nip2p_kStreamAttributeWriteOverflow, and nip2p_kStreamAttributeReaderUnderflow. Querying the attribute gives the current state of the attribute, so it is possible to miss an event such as the stream becoming enabled if it becomes disabled again before the attribute is queried.