[Remoting series] v. Channels

Source: Internet
Author: User

A channel is the bearer platform of the remoting system. It processes communications between clients and servers, including cross-origin communication, message transmission, and object encoding. The channel must implement the ichannel interface, and the inherited versions of ichannelpolicer and ichannelsender are provided based on the communication direction. The remoting framework provides us with the IPC, TCP, and HTTP implementation versions. Of course, we can also find the implementation versions of other protocols on the network.

Tcpserverchannel Channel =   New Tcpserverchannel ( 801 );
Channelservices. registerchannel (channel, False );

We can use the ingress class channelservices for management.ProgramChannels in the domain, such as registration and cancellation. Multiple channels can be used in the program domain at the same time. Each channel must provide a unique name for channelservices to manage. At the same time, the channel will be automatically destroyed as the program domain exits.

Tcpserverchannel Channel =   New Tcpserverchannel ( " Tcp801 " , 801 );
Channelservices. registerchannel (channel, False );

Ichannel C2 = Channelservices. getchannel ( " Tcp801 " );
Console. writeline (object. referenceequals (Channel, C2 ));

Channel. stoplistening ( Null );
Channel. startlistening ( Null );

Foreach (Ichannel C In Channelservices. registeredchannels)
{
Console. writeline (C. channelname );
}

Channelservices. unregisterchannel (Channel );

A channel contains a sink chain composed of multiple receivers ). A receiver is used to process incoming and outgoing messages between the client and the server, such as formattersink, transportsink, or stackbuildersink. Each receiver can implement iclientchannelsink or iserverchannelsink.

Remoting creates a receiver using the Channel sink provider (iclientchannelsinkprovider, iclientformattersinkprovider, or the iserverchannelsinkprovider interface). The existing providers include binaryclientformattersinkprovider. / Binaryserverformattersinkprovider, soapclientformattersinkprovider / Soapserverformattersinkprovider.

In the client receiving chain, the first receiver is usually the iclientformattersink and must implement imessagesink. The proxy finds the receiver through the channel receiving provider, transmits the message to all receivers in the chain through the interface method, and finally sends the receiver to the server. Similarly, the receiver at the end of the server is the formatting program receiver and the stack generator receiver, which respectively execute deserialization and convert messages into the corresponding call stack.

Tcpserverchannel Channel =   New Tcpserverchannel ( " Tcp801 " , 801 , New Binaryserverformattersinkprovider ());
Channelservices. registerchannel (channel, False );



Tcpclientchannel Channel =   New Tcpclientchannel ( " Tcp801 " , New Binaryclientformattersinkprovider ());
Channelservices. registerchannel (channel, False );

You only need to look at the code of binaryclientformattersinkprovider and binaryclientformattersink to easily understand how to use the Provider Model to construct a receipt chain.

Binaryclientformattersinkprovider
Public Iclientchannelsink createsink (ichannelsender channel, String URL, Object Remotechanneldata)
{
Iclientchannelsink sink1 =   Null ;
If ( This . _ Next ! =   Null )
{
Sink1 =   This . _ Next. createsink (Channel, URL, remotechanneldata );
If (Sink1 =   Null )
{
Return Null;
}
}
Sinkchannelprotocol Protocol1 = Corechannel. determinechannelprotocol (Channel );
Binaryclientformattersink sink2 =   New Binaryclientformattersink (sink1 );
Sink2.20.deversioning =   This . _ Includeversioning;
Sink2.strictbinding =   This . _ Strictbinding;
Sink2.channelprotocol = Protocol1;
Return Sink2;
}

Binaryclientformattersink
Public Binaryclientformattersink (iclientchannelsink nextsink)
{
This. _ Includeversioning= True;
This. _ Channelprotocol=Sinkchannelprotocol. Other;
This. _ Nextsink=Nextsink;
}

Public Iclientchannelsink nextchannelsink
{
Get
{
Return This. _ Nextsink;
}
}

 

the receiver in the channel can be "inserted", which means we can implement our own receiver, and assemble it into the channel receiving chain. For example, encrypt messages or compress data streams.
For more information, see
. net remoting customization made easy: Custom sinks "
" How to customize sink extension. net remoting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.