Use network streams to stream data between two or more applications.
To transmit data using network streams, you must develop the code to write and read data on both the host and target applications.
What to Use
What to Do
-
Create the following diagram in a VI for the target application. This diagram illustrates the entire network stream code on the target application.
Customize the gray sections for your unique programming goals.
|
The
Create Network Stream Writer Endpoint
node creates the writer endpoint in the
target application.
|
|
The writer endpoint establishes a connection with the reader endpoint using the
reader URL.
Refer to the
Details
tab of the
Create Network Stream Writer Endpoint
or the
Create Network Stream Reader Endpoint
nodes for help specifying endpoint URLs.
|
|
The
Write Single Element to Stream
node continuously adds one data point to the FIFO buffer, which the reader endpoint on the host application reads from.
Note
You can use the
Write Multiple Elements to the Stream
node to add more than one data point at a time.
|
|
To specify the amount of time to wait between loop iterations, wire the desired time duration to the input of the
Wait
node. The
Wait
node waits until the value of the operating system's counter increases by an amount equal to the input you specify.
|
|
Data streams continuously until the user clicks the
Stop
button on the target application, which notifies the reader endpoint on the host application that the stream is no longer valid.
Note
You can also use the
Stop
button on the host application to stop streaming data.
|
|
The
Flush Stream
node transfers all data to the reader endpoint before data flow resumes. It ensures that all data still residing in the writer endpoint buffer immediately transfer across the network. The
Flush Stream
node then waits until either the specified wait condition is met or the timeout expires.
Note
Use this node before the
Destroy Stream Endpoint
node to ensure the reader endpoint receives all data before destroying the writer endpoint. This prevents data loss.
|
|
The
Destroy Stream Endpoint
node destroys the writer endpoint. To destroy a stream completely, however, you must destroy both the reader and writer endpoints.
|
-
Create the following diagram in a VI for the host application. This diagram illustrates the network stream code on the host application.
Customize the gray sections for your unique programming goals.
|
The
Create Network Stream Reader Endpoint
node creates the reader endpoint on the host application. Once the reader endpoint exists, the writer endpoint will attempt to connect with it.
|
|
The
Read Single Element from Stream
node continuously consumes data from the FIFO buffer originally sent from the writer loop.
Note
The
Read Multiple Elements from Stream
node consumes batches of data from the buffer. You can use this node even if you used the
Write Single Element to Stream
node in the writer loop.
|
|
When the
Destroy Stream Endpoint
node destroys the writer endpoint, the reader endpoint receives an error, which causes the data flow to exit the
While Loop.
Note
When the network disconnects, an endpoint becomes inactive. The other endpoint continuously tries to reestablish communication with the inactive endpoint in the background. This background process continues until the connection is repaired or until the inactive endpoint is destroyed.
|
|
The
Destroy Stream Endpoint
node destroys the reader endpoint, which destroys the stream.
|
After you finish developing your target and host applications, your target and host applications communicate using a network stream when you run the applications simultaneously. Be sure to run the target application first to ensure the writer endpoint can locate the reader endpoint.
Troubleshooting
-
If you have trouble establishing a connection, try the following troubleshooting strategies:
-
Make sure you are using the
recommended firewall settings.
-
(Windows 7) Make sure your Ethernet adapters are set to a "Home" or "Work" setting. If your network is set to Private, you may receive an error.
-
Make sure your endpoint URL is specified properly.
Refer to the
Details
tab of the
Create Network Stream Writer Endpoint
or the
Create Network Stream Reader Endpoint
nodes for help specifying endpoint URLs.
-
Make sure you are not reusing endpoint names. If a name collision occurs, your intended endpoints will not connect and will error out. To avoid name collisions, consider using globally unique identifiers (GUID).
-
Make sure the endpoints you want to use are not connected to other endpoints. An endpoint can only connect to one other endpoint at a time.
-
Make sure you are specifying an endpoint that exists.
-
Make sure you are using compatible endpoints.
-
You cannot connect two reader endpoints to each other nor two writer endpoints to each other. You must use a writer endpoint and a reader endpoint.
-
The endpoints must have the same data type.
-
If you have trouble streaming data after establishing a connection, try the following troubleshooting strategies:
-
Make sure the nodes are compatible with one another. You cannot wire a
Read Multiple Elements from Stream
node or a
Read Single Element from Stream
node to a
Create Network Stream Writer Endpoint
node. You also cannot wire a
Write Multiple Elements to Stream
node, a
Write Single Element to Stream
node, or a
Flush Stream
node to a
Create Network Stream Reader Endpoint
node.
-
Make sure you are not reading or writing a number of elements larger than the
endpoint buffer size.
Examples
Search within the programming environment to access the following installed example: