IrDAClientGetStream Method

Returns the NetworkStream used to send and receive data.

Definition

Namespace: InTheHand.Net.Sockets
Assembly: InTheHand.Net.IrDA (in InTheHand.Net.IrDA.dll) Version: 4.0.2+5cdf1cfd21064ea31c5de33d160200ca1c4bc218
C#
public NetworkStream GetStream()

Return Value

NetworkStream
The underlying NetworkStream.

Remarks

GetStream returns a NetworkStream that you can use to send and receive data. The NetworkStream class inherits from the Stream class, which provides a rich collection of methods and properties used to facilitate network communications.

You must call the Connect(IrDAEndPoint) method, or one of its overloads, first, or the GetStream method will throw an InvalidOperationException. After you have obtained the NetworkStream, call the Write(Byte, Int32, Int32) method to send data to the remote host. Call the Read(Byte, Int32, Int32) method to receive data arriving from the remote host. Both of these methods block until the specified operation is performed. You can avoid blocking on a read operation by checking the DataAvailable property. A true value means that data has arrived from the remote host and is available for reading. In this case, Read is guaranteed to complete immediately. If the remote host has shutdown its connection, Read will immediately return with zero bytes.

  Note

Closing the NetworkStream closes the connection. Similarly Closing, Disposing, or the finalization of the IrDAClient Disposes the NetworkStream. This is new behaviour post 2.0.60828.0.

  Note

If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. After you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.

Exceptions

InvalidOperationException The IrDAClient is not connected to a remote host.
ObjectDisposedException The IrDAClient has been closed.

See Also