This documentation is archived and is not being maintained.

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 IChannelReceiver : IChannel

The receiving side of channels must expose the IChannelReceiver interface.

class MyCustomChannel : IChannelReceiver
{
   private ChannelDataStore myChannelData;
   private int myChannelPriority = 25;
   // Set the 'ChannelName' to 'MyCustomChannel'. 
   private string myChanneName = "tcp";
   // Implement 'ChannelName' property. 
   private TcpListener myTcpListener;
   private int myPortNo;
   private bool myListening = false;
   private Thread myThread;
   public MyCustomChannel(int portNo)
   {  
      myPortNo = portNo;
      string [] myURI = new string[1];
      myURI[0] = Dns.Resolve(Dns.GetHostName()).AddressList[0] + ":" +
                                                         portNo.ToString();
      // Store the 'URI' in 'myChannelDataStore'.
      myChannelData = new ChannelDataStore(myURI);
      // Create 'myTcpListener' to listen at the 'myPortNo' port.
      myTcpListener = new TcpListener(myPortNo);
      // Create the thread 'myThread'.
      myThread = new Thread(new ThreadStart(myTcpListener.Start));
      this.StartListening(null);
   }
   public string ChannelName
   {
      get
      {
         return myChanneName;
      }
   }
   public int ChannelPriority
   {
      get
      {
         return myChannelPriority;
      }
   }
   public string Parse(string myUrl, out string objectURI)
   {
      Regex myRegex = new 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. 
   public object ChannelData
   {
      get
      {
         return myChannelData;
      }
   }

   // Create and send the object URL. 
   public string[] GetUrlsForUri(string objectURI)
   {
      string[] myString = new string[1];
      myString[0] = Dns.Resolve(Dns.GetHostName()).AddressList[0]
                                                         + "/" + objectURI;
      return myString;
   }

   // Start listening to the port. 
   public void StartListening(object data)
   {
      if(myListening == false)
      {
         myTcpListener.Start();
         myListening = true;
         Console.WriteLine("Server Started Listening !!!");
      }
   }

   // Stop listening to the port. 
   public void StopListening(object data)
   {
      if(myListening == true)
      {
         myTcpListener.Stop();
         myListening = false;
         Console.WriteLine("Server Stopped Listening !!!");
      }
   }
}
__gc 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(S"tcp"), myListening(false) {}
   MyCustomChannel(int portNo)
   {  
      myPortNo = portNo;
      String* myURI[] = new String*[1];
      myURI[0] = String::Concat( Dns::Resolve(Dns::GetHostName())->AddressList[0], S":", __box(portNo));
      // Store the 'URI' in 'myChannelDataStore'.
      myChannelData = new ChannelDataStore(myURI);
      // Create 'myTcpListener' to listen at the 'myPortNo' port.
      myTcpListener = new TcpListener(myPortNo);
      // Create the thread 'myThread'.
      myThread = new Thread(new ThreadStart(myTcpListener, &TcpListener::Start));
      this->StartListening(0);
   }

   __property String* get_ChannelName()
   {
      return myChannelName;
   }

   __property int get_ChannelPriority()
   {
      return myChannelPriority;
   }

   String* Parse(String* myUrl, [Out]String** objectURI)
   {
      Regex* myRegex = new Regex(S"/",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* get_ChannelData()
   {
      return myChannelData;
   }


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

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

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: