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

NameDescription
System_CAPS_pubpropertyChannelData

Gets the channel-specific data.

System_CAPS_pubpropertyChannelName

Gets the name of the channel.(Inherited from IChannel.)

System_CAPS_pubpropertyChannelPriority

Gets the priority of the channel.(Inherited from IChannel.)

NameDescription
System_CAPS_pubmethodGetUrlsForUri(String^)

Returns an array of all the URLs for a URI.

System_CAPS_pubmethodParse(String^, String^%)

Returns the object URI as an out parameter, and the URI of the current channel as the return value.(Inherited from IChannel.)

System_CAPS_pubmethodStartListening(Object^)

Instructs the current channel to start listening for requests.

System_CAPS_pubmethodStopListening(Object^)

Instructs the current channel to stop listening for requests.

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
Available since 1.1
Return to top
Show: