Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 _
	Inherits IChannel

The IChannelReceiver type exposes the following members.

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.)
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.

The receiving side of channels must expose the IChannelReceiver interface.

Class MyCustomChannel
      Implements IChannelReceiver 
      Private myChannelData As ChannelDataStore
      Private myChannelPriority As Integer = 25
      ' Set the 'ChannelName' to 'MyCustomChannel'. 
      Private myChanneName As String = "tcp" 
      ' Implement 'ChannelName' property. 
      Private myTcpListener As TcpListener
      Private myPortNo As Integer 
      Private myListening As Boolean = False 
      Private myThread As Thread

      Public Sub New(ByVal portNo As Integer)
         myPortNo = portNo
      Dim myURI(0) As String
      myURI(0) = Dns.Resolve(Dns.GetHostName()).AddressList(0).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(AddressOf myTcpListener.Start))
      End Sub 'New 

      Public ReadOnly Property ChannelName() As String Implements IChannelReceiver.ChannelName
         Return myChanneName
      End Get 
      End Property 

      Public ReadOnly Property ChannelPriority() As Integer _
                                          Implements IChannelReceiver.ChannelPriority
         Return myChannelPriority
      End Get 
      End Property 

      Public Function Parse(ByVal myUrl As String, ByRef objectURI As String) As String _
                                                      Implements IChannelReceiver.Parse
      Dim myRegex As New Regex("/", RegexOptions.RightToLeft)
      ' Check for '/' in 'myUrl' from Right to left. 
      Dim myMatch As Match = myRegex.Match(myUrl)
      ' Get the object URI.
      objectURI = myUrl.Substring(myMatch.Index)
      ' Return the channel url. 
      Return myUrl.Substring(0, myMatch.Index)
      End Function 'Parse
      ' Implementation of 'IChannelReceiver' interface. 

   Public ReadOnly Property ChannelData() As Object Implements IChannelReceiver.ChannelData
         Return myChannelData
      End Get 
   End Property 

   ' Create and send the object URL. 
   Public Function GetUrlsForUri(ByVal objectURI As String) As String() _
                                             Implements IChannelReceiver.GetUrlsForUri
      Dim myString(0) As String
      myString(0) = Dns.Resolve(Dns.GetHostName()).AddressList(0).ToString() + "/" + objectURI
      Return myString
   End Function 'GetUrlsForUri

   ' Start listening to the port. 
   Public Sub StartListening(ByVal data As Object) Implements IChannelReceiver.StartListening
      If myListening = False Then
          myListening = True
          Console.WriteLine("Server Started Listening !!!")
      End If 
   End Sub 'StartListening

   ' Stop listening to the port. 
   Public Sub StopListening(ByVal data As Object) Implements IChannelReceiver.StopListening
      If myListening = True Then
          myListening = False
          Console.WriteLine("Server Stopped Listening !!!")
      End If 
   End Sub 'StopListening
End Class 'MyCustomChannel 

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.