Click or drag to resize

IPacketIOService Interface

Protocol packet and stream IO service. IPacketIOService DataChanged events will pass PacketChangedEventArgs.

Namespace: Demo3D.Net
Assembly: Demo3D.IO (in Demo3D.IO.dll) Version: 19.00.00
Syntax
C#
public interface IPacketIOService : INotifyDataChanged

The IPacketIOService type exposes the following members.

Properties
 NameDescription
Public propertyCanSubscribe Returns true if data changes can be subscribed to.
(Inherited from INotifyDataChanged)
Public propertyDataSubscribed Returns true if data changes are currently subscribed to.
(Inherited from INotifyDataChanged)
Public propertyPduSize Gets the PDU size (or -1 for byte streams).
Top
Methods
 NameDescription
Public methodAddDataChanged Add a handler for the DataChanged event.
(Inherited from INotifyDataChanged)
Public methodReadAsync Gets a data buffer for reading.
Public methodRemoveDataChanged Remove a handler from the DataChanged event.
(Inherited from INotifyDataChanged)
Public methodWrite Gets a data buffer for writing.
Top
Events
 NameDescription
Public eventDataChanged Occurs when data has arrived or changed.
(Inherited from INotifyDataChanged)
Top
Extension Methods
 NameDescription
Public Extension MethodCode exampleGetEventQueue Subscribes to data changed events and returns a NotifyDataChangedEventQueue.
(Defined by NotifyDataChanged)
Public Extension MethodRead Gets a data buffer for reading.
(Defined by PacketIOService)
Public Extension MethodRead Reads data.
(Defined by PacketIOService)
Public Extension MethodRead Gets a data buffer for reading.
(Defined by PacketIOService)
Public Extension MethodReadAsync Gets a data buffer for reading.
(Defined by PacketIOService)
Public Extension MethodReadAsync Reads data.
(Defined by PacketIOService)
Public Extension MethodReadAsync Gets a data buffer for reading.
(Defined by PacketIOService)
Public Extension MethodReply Gets a data buffer for writing, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodReply Writes data, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodReply Writes data, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodReply Writes data, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodReplyAsync Writes data, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodReplyAsync Writes data, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodReplyAsync Writes data, in reply to a given request.
(Defined by PacketIOService)
Public Extension MethodWrite Writes data.
(Defined by PacketIOService)
Public Extension MethodWrite Writes data.
(Defined by PacketIOService)
Public Extension MethodWrite Gets a data buffer for writing.
(Defined by PacketIOService)
Public Extension MethodWrite Writes data.
(Defined by PacketIOService)
Public Extension MethodWriteAsync Writes data.
(Defined by PacketIOService)
Public Extension MethodWriteAsync Writes data.
(Defined by PacketIOService)
Public Extension MethodWriteAsync Writes data.
(Defined by PacketIOService)
Top
Remarks

Protocols can implement IByteStreamService or IMessageStreamService instead of this service. IByteStreamService and IMessageStreamService are much simpler to implement, and this service will be offered on any protocol that supports either one of them.

In contract to the simpler services, IPacketIOService offers Read and Write methods that return IPacketIO, and is specifically designed to support stacked protocols (eg TCP -> TPKT -> COTP -> S7P, or TCP -> EIP -> CPF -> CIP). It also offers a common interface so that higher level protocols can run regardless of the low-level data transport (eg the Modbus protocol can work aginst this common API and then operate over either TCP or UDP). Also it offers a common interface so that protocols such as Windows pipes can present a single API that works whether the pipe is operating in byte or message mode.

Reading: IPacketReader provides a deserialization API similar to BinaryReader. It also supports multiple threads reading from the low level protocol data stream in parallel. The PacketReader locks the lower level data stream while the caller reads data in (usually a small header eg TPKT) followed by the data payload, and then unlocks.

Multi-threaded reading is rare but useful, for example where there's a thread pool reading packets and servicing them in parallel, or notifying them upwards in parallel.

Writing: IPacketWriter provides a serialization API similar to BinaryWriter. It's specifically optimised for stacked protocols where the lower level protocol creates a buffer with a header and the layered protocols then write directly into the data payload part of the buffer, minimising data copying.

It also provides support for packets divided into sections, such as S7P where there are multiple headers followed by multiple corresponding data sections.

And, it allows packets to be replayed. The packet is constructed once and retained. The caller can modify the packet data payload and call Flush again. Lower level protocols get notified that the packet is being retransmitted and can recompute header information (data lengths, checksums, transaction id's, etc).

See Also