Hybrid transmission data summarized carding

A, Connector class

The Connector is the Sender and Receiver SocketChannel implementation class, so Selector has a function of receiving and sending.

When sending the package into a SocketChannel StringSendPacket, upon receiving the StringReceivePacket resolved to Striing

 

Second, the process of transmission and reception

The sender and receiver as a whole, are made SocketChannelAdapter in SocketChannel achieve.

First, the data IoArgs read (write).

For event scheduling by IoProvider, including reading events scheduled ReadSelector, write events scheduled WriteSelector. sender or receiver will be registered by IoProvider.

It will trigger a read or write operation corresponding to read, write event mechanism, and the thread through the callback back. Completion callback event truly send, read operations.

 

 

Third, the class used to solve data problems arising in the course of the outgoing

 

When transmitting, the end of the queue into Packet data, and then obtaining a Packet from the queue head, writes data in the Packet IoArgs inside.

Then IoArgs registered to Sender, asynchronous method call sent by the Sender, will IoArgs, listener as a parameter, when the sender through Selector event callback mechanism, send data IoArgs in. After the transmission is complete, perform transmission completion callback. The listener is held by the sender. If no data transmission is completed, the process repeats.

Published 174 original articles · won praise 115 · views 830 000 +

Guess you like

Origin blog.csdn.net/nicolelili1/article/details/104339137