Export (0) Print
Expand All

IChannelReceiver Interface

Provides required functions and properties for the receiver channels.

Namespace:  System.Runtime.Remoting.Channels
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public interface class IChannelReceiver : IChannel

The IChannelReceiver type exposes the following members.

  NameDescription
Public propertyChannelDataGets the channel-specific data.
Public propertyChannelNameGets the name of the channel. (Inherited from IChannel.)
Public propertyChannelPriorityGets the priority of the channel. (Inherited from IChannel.)
Top

  NameDescription
Public methodGetUrlsForUriReturns an array of all the URLs for a URI.
Public methodParseReturns the object URI as an out parameter, and the URI of the current channel as the return value. (Inherited from IChannel.)
Public methodStartListeningInstructs the current channel to start listening for requests.
Public methodStopListeningInstructs the current channel to stop listening for requests.
Top

The receiving side of channels must expose the IChannelReceiver interface.

ref class MyCustomChannel: public IChannelReceiver
{
private:
   ChannelDataStore^ myChannelData;
   int myChannelPriority;

   // Set the 'ChannelName' to 'MyCustomChannel'.
   String^ myChannelName;

   // Implement 'ChannelName' property.
   TcpListener^ myTcpListener;
   int myPortNo;
   bool myListening;
   Thread^ myThread;

public:
   MyCustomChannel()
      : myChannelPriority( 25 ), myChannelName( "tcp" ), myListening( false )
   {}

   MyCustomChannel( int portNo )
   {
      myPortNo = portNo;
      array<String^>^myURI = gcnew array<String^>(1);
      myURI[ 0 ] = String::Concat( Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ], ":", portNo );

      // Store the 'URI' in 'myChannelDataStore'.
      myChannelData = gcnew ChannelDataStore( myURI );

      // Create 'myTcpListener' to listen at the 'myPortNo' port.
      myTcpListener = gcnew TcpListener( myPortNo );

      // Create the thread 'myThread'.
      myThread = gcnew Thread( gcnew ThreadStart( myTcpListener, &TcpListener::Start ) );
      this->StartListening( nullptr );
   }

   property String^ ChannelName 
   {
      virtual String^ get()
      {
         return myChannelName;
      }
   }

   property int ChannelPriority 
   {
      virtual int get()
      {
         return myChannelPriority;
      }
   }
   virtual String^ Parse( String^ myUrl, [Out]String^% objectURI )
   {
      Regex^ myRegex = gcnew Regex( "/",RegexOptions::RightToLeft );

      // Check for '/' in 'myUrl' from Right to left.
      Match^ myMatch = myRegex->Match(myUrl);

      // Get the object URI.
      objectURI = myUrl->Substring( myMatch->Index );

      // Return the channel url. 
      return myUrl->Substring( 0, myMatch->Index );
   }

   // Implementation of 'IChannelReceiver' interface. 
   property Object^ ChannelData 
   {
      virtual Object^ get()
      {
         return myChannelData;
      }
   }

   // Create and send the object URL. 
   virtual array<String^>^ GetUrlsForUri( String^ objectURI )
   {
      array<String^>^myString = gcnew array<String^>(1);
      myString[ 0 ] = String::Concat( Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ], "/", objectURI );
      return myString;
   }

   // Start listening to the port. 
   virtual void StartListening( Object^ data )
   {
      if ( myListening == false )
      {
         myTcpListener->Start();
         myListening = true;
         Console::WriteLine( "Server Started Listening !!!" );
      }
   }

   // Stop listening to the port. 
   virtual void StopListening( Object^ data )
   {
      if ( myListening == true )
      {
         myTcpListener->Stop();
         myListening = false;
         Console::WriteLine( "Server Stopped Listening !!!" );
      }
   }
};

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft