当前位置: 首页>>代码示例>>C#>>正文


C# IChannelReceiver接口代码示例

本文整理汇总了C#中System.Runtime.Remoting.Channels.IChannelReceiver接口的典型用法代码示例。如果您正苦于以下问题:C# IChannelReceiver接口的具体用法?C# IChannelReceiver怎么用?C# IChannelReceiver使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。


IChannelReceiver接口属于System.Runtime.Remoting.Channels命名空间,在下文中一共展示了IChannelReceiver接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MyCustomChannel

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 !!!");
      }
   }
}
开发者ID:.NET开发者,项目名称:System.Runtime.Remoting.Channels,代码行数:89,代码来源:IChannelReceiver


注:本文中的System.Runtime.Remoting.Channels.IChannelReceiver接口示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。