public TcpChannel

  1. // ==++==
  2. // 
  3. //   
  4. //    Copyright (c) 2002 Microsoft Corporation.  All rights reserved.
  5. //   
  6. //    The use and distribution terms for this software are contained in the file
  7. //    named license.txt, which can be found in the root of this distribution.
  8. //    By using this software in any fashion, you are agreeing to be bound by the
  9. //    terms of this license.
  10. //   
  11. //    You must not remove this notice, or any other, from this software.
  12. //   
  13. // 
  14. // ==--==
  15. //==========================================================================
  16. //  File:       CombinedTcpChannel.cs
  17. //
  18. //  Summary:    Merges the client and server TCP channels
  19. //
  20. //  Classes:    public TcpChannel
  21. //
  22. //==========================================================================
  23. using System;
  24. using System.Collections;
  25. using System.Runtime.Remoting;
  26. using System.Runtime.Remoting.Messaging;
  27. namespace System.Runtime.Remoting.Channels.Tcp
  28. {
  29.     /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel"]/*' />
  30.     public class TcpChannel : IChannelReceiver, IChannelSender
  31.     {
  32.         private TcpClientChannel  _clientChannel = null// client channel
  33.         private TcpServerChannel  _serverChannel = null// server channel
  34.     
  35.         private int    _channelPriority = 1;  // channel priority
  36.         private String _channelName = "tcp"// channel name
  37.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.TcpChannel"]/*' />
  38.         public TcpChannel()
  39.         {
  40.             _clientChannel = new TcpClientChannel();
  41.             // server channel will not be activated.
  42.         } // TcpChannel
  43.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.TcpChannel1"]/*' />
  44.         public TcpChannel(int port) : this()
  45.         {
  46.             _serverChannel = new TcpServerChannel(port);
  47.         } // TcpChannel
  48.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.TcpChannel2"]/*' />
  49.         public TcpChannel(IDictionary properties, 
  50.                           IClientChannelSinkProvider clientSinkProvider,
  51.                           IServerChannelSinkProvider serverSinkProvider)
  52.         {
  53.             Hashtable clientData = new Hashtable();
  54.             Hashtable serverData = new Hashtable();
  55.             bool portFound = false;
  56.         
  57.             // divide properties up for respective channels
  58.             if (properties != null)
  59.             {
  60.                 foreach (DictionaryEntry entry in properties)
  61.                 {
  62.                     switch ((String)entry.Key)
  63.                     {
  64.                     // general channel properties
  65.                     case "name": _channelName = (String)entry.Value; break;
  66.                     case "priority": _channelPriority = Convert.ToInt32((String)entry.Value); break;
  67.                     // client properties (none yet)
  68.                     // server properties
  69.                     case "bindTo": serverData["bindTo"] = entry.Value; break;
  70.                     case "machineName": serverData["machineName"] = entry.Value; break
  71.                     
  72.                     case "port"
  73.                     {
  74.                         serverData["port"] = entry.Value; 
  75.                         portFound = true;
  76.                         break;
  77.                     }
  78.                     case "rejectRemoteRequests": serverData["rejectRemoteRequests"] = entry.Value; break;
  79.                     case "suppressChannelData": serverData["suppressChannelData"] = entry.Value; break;
  80.                     case "useIpAddress": serverData["useIpAddress"] = entry.Value; break;
  81.                     default
  82.                          throw new ArgumentException(
  83.                             String.Format(
  84.                                 CoreChannel.GetResourceString(
  85.                                     "Remoting_Channels_BadCtorArgs"),
  86.                                 entry.Key));
  87.                     }
  88.                 }                    
  89.             }
  90.             _clientChannel = new TcpClientChannel(clientData, clientSinkProvider);
  91.             if (portFound)
  92.                 _serverChannel = new TcpServerChannel(serverData, serverSinkProvider);
  93.         } // TcpChannel
  94.         // 
  95.         // IChannel implementation
  96.         //
  97.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.ChannelPriority"]/*' />
  98.         public int ChannelPriority
  99.         {
  100.             get { return _channelPriority; }    
  101.         } // ChannelPriority
  102.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.ChannelName"]/*' />
  103.         public String ChannelName
  104.         {
  105.             get { return _channelName; }
  106.         } // ChannelName
  107.         // returns channelURI and places object uri into out parameter
  108.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.Parse"]/*' />
  109.         public String Parse(String url, out String objectURI)
  110.         {            
  111.             return TcpChannelHelper.ParseURL(url, out objectURI);
  112.         } // Parse
  113.         
  114.         //
  115.         // end of IChannel implementation
  116.         //
  117.         //
  118.         // IChannelSender implementation
  119.         //
  120.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.CreateMessageSink"]/*' />
  121.         public IMessageSink CreateMessageSink(String url, Object remoteChannelData, 
  122.                                                       out String objectURI)
  123.         {
  124.             return _clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
  125.         } // CreateMessageSink
  126.         //
  127.         // end of IChannelSender implementation
  128.         //
  129.         //
  130.         // IChannelReceiver implementation
  131.         //
  132.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.ChannelData"]/*' />
  133.         public Object ChannelData
  134.         {
  135.             get 
  136.             {
  137.                 if (_serverChannel != null)
  138.                     return _serverChannel.ChannelData;
  139.                 else
  140.                     return null;
  141.             }
  142.         } // ChannelData
  143.       
  144.                 
  145.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.GetUrlsForUri"]/*' />
  146.         public String[] GetUrlsForUri(String objectURI)
  147.         {
  148.             if (_serverChannel != null)
  149.                 return _serverChannel.GetUrlsForUri(objectURI);
  150.             else
  151.                 return null;
  152.         } // GetUrlsforURI
  153.         
  154.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.StartListening"]/*' />
  155.         public void StartListening(Object data)
  156.         {
  157.             if (_serverChannel != null)
  158.                 _serverChannel.StartListening(data);
  159.         } // StartListening
  160.         /// <include file='doc/CombinedTcpChannel.uex' path='docs/doc[@for="TcpChannel.StopListening"]/*' />
  161.         public void StopListening(Object data)
  162.         {
  163.             if (_serverChannel != null)
  164.                 _serverChannel.StopListening(data);
  165.         } // StopListening
  166.         //
  167.         // IChannelReceiver implementation
  168.         //
  169.     
  170.     } // class TcpChannel
  171. // namespace System.Runtime.Remoting.Channels.Tcp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值