IPacketIOService Interface |
Namespace: Demo3D.Net
public interface IPacketIOService : INotifyDataChanged
The IPacketIOService type exposes the following members.
| Name | Description | |
|---|---|---|
| CanSubscribe |
Returns true if data changes can be subscribed to.
(Inherited from INotifyDataChanged.) | |
| DataSubscribed |
Returns true if data changes are currently subscribed to.
(Inherited from INotifyDataChanged.) | |
| PduSize |
Gets the PDU size (or -1 for byte streams).
|
| Name | Description | |
|---|---|---|
| AddDataChanged |
Add a handler for the DataChanged event.
(Inherited from INotifyDataChanged.) | |
| ReadAsync |
Gets a data buffer for reading.
| |
| RemoveDataChanged |
Remove a handler from the DataChanged event.
(Inherited from INotifyDataChanged.) | |
| Write |
Gets a data buffer for writing.
|
| Name | Description | |
|---|---|---|
| DataChanged |
Occurs when data has arrived or changed.
(Inherited from INotifyDataChanged.) |
| Name | Description | |
|---|---|---|
| GetEventQueue |
Subscribes to data changed events and returns a NotifyDataChangedEventQueue.
(Defined by NotifyDataChanged.) | |
| Read | Overloaded.
Gets a data buffer for reading.
(Defined by PacketIOService.) | |
| Read(Int32) | Overloaded.
Reads data.
(Defined by PacketIOService.) | |
| Read(Endian, BinaryTextEncoding) | Overloaded.
Gets a data buffer for reading.
(Defined by PacketIOService.) | |
| ReadAsync | Overloaded.
Gets a data buffer for reading.
(Defined by PacketIOService.) | |
| ReadAsync(Int32) | Overloaded.
Reads data.
(Defined by PacketIOService.) | |
| ReadAsync(Endian, BinaryTextEncoding) | Overloaded.
Gets a data buffer for reading.
(Defined by PacketIOService.) | |
| Reply(IPacketIO) | Overloaded.
Gets a data buffer for writing, in reply to a given request.
(Defined by PacketIOService.) | |
| Reply(IPacketIO, ArraySegmentByte) | Overloaded.
Writes data, in reply to a given request.
(Defined by PacketIOService.) | |
| Reply(IPacketIO, Byte) | Overloaded.
Writes data, in reply to a given request.
(Defined by PacketIOService.) | |
| Reply(IPacketIO, Byte, Int32, Int32) | Overloaded.
Writes data, in reply to a given request.
(Defined by PacketIOService.) | |
| ReplyAsync(IPacketIO, ArraySegmentByte) | Overloaded.
Writes data, in reply to a given request.
(Defined by PacketIOService.) | |
| ReplyAsync(IPacketIO, Byte) | Overloaded.
Writes data, in reply to a given request.
(Defined by PacketIOService.) | |
| ReplyAsync(IPacketIO, Byte, Int32, Int32) | Overloaded.
Writes data, in reply to a given request.
(Defined by PacketIOService.) | |
| Write(ArraySegmentByte) | Overloaded.
Writes data.
(Defined by PacketIOService.) | |
| Write(Byte) | Overloaded.
Writes data.
(Defined by PacketIOService.) | |
| Write(Endian, BinaryTextEncoding) | Overloaded.
Gets a data buffer for writing.
(Defined by PacketIOService.) | |
| Write(Byte, Int32, Int32) | Overloaded.
Writes data.
(Defined by PacketIOService.) | |
| WriteAsync(ArraySegmentByte) | Overloaded.
Writes data.
(Defined by PacketIOService.) | |
| WriteAsync(Byte) | Overloaded.
Writes data.
(Defined by PacketIOService.) | |
| WriteAsync(Byte, Int32, Int32) | Overloaded.
Writes data.
(Defined by PacketIOService.) |
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).