TcpClientChannel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // System.Runtime.Remoting.Channels.Tcp.TcpClientChannel.cs
  3. //
  4. // Author: Dietmar Maurer ([email protected])
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // 2002 (C) Copyright, Ximian, Inc.
  8. //
  9. using System.Collections;
  10. using System.IO;
  11. using System.Net.Sockets;
  12. using System.Runtime.Remoting.Messaging;
  13. using System.Runtime.Remoting.Channels;
  14. using System.Threading;
  15. namespace System.Runtime.Remoting.Channels.Tcp
  16. {
  17. public class TcpClientChannel : IChannelSender, IChannel
  18. {
  19. int priority = 1;
  20. string name = "tcp";
  21. IClientChannelSinkProvider _sinkProvider;
  22. public TcpClientChannel ()
  23. {
  24. }
  25. public TcpClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
  26. {
  27. object val = properties ["name"];
  28. if (val != null) name = val as string;
  29. val = properties ["priority"];
  30. if (val != null) priority = Convert.ToInt32 (val);
  31. if (sinkProvider != null)
  32. {
  33. _sinkProvider = sinkProvider;
  34. // add the tcp provider at the end of the chain
  35. IClientChannelSinkProvider prov = sinkProvider;
  36. while (prov.Next != null) prov = prov.Next;
  37. prov.Next = new TcpClientTransportSinkProvider ();
  38. // Note: a default formatter is added only when
  39. // no sink providers are specified in the config file.
  40. }
  41. else
  42. {
  43. _sinkProvider = new BinaryClientFormatterSinkProvider ();
  44. _sinkProvider.Next = new TcpClientTransportSinkProvider ();
  45. }
  46. }
  47. public TcpClientChannel (string name, IClientChannelSinkProvider sinkProvider)
  48. {
  49. this.name = name;
  50. _sinkProvider = sinkProvider;
  51. // add the tcp provider at the end of the chain
  52. IClientChannelSinkProvider prov = sinkProvider;
  53. while (prov.Next != null) prov = prov.Next;
  54. prov.Next = new TcpClientTransportSinkProvider ();
  55. }
  56. public string ChannelName
  57. {
  58. get {
  59. return name;
  60. }
  61. }
  62. public int ChannelPriority
  63. {
  64. get {
  65. return priority;
  66. }
  67. }
  68. public IMessageSink CreateMessageSink (string url,
  69. object remoteChannelData,
  70. out string objectURI)
  71. {
  72. if (url == null && remoteChannelData != null) {
  73. IChannelDataStore ds = remoteChannelData as IChannelDataStore;
  74. if (ds != null && ds.ChannelUris.Length > 0)
  75. url = ds.ChannelUris [0];
  76. else {
  77. objectURI = null;
  78. return null;
  79. }
  80. }
  81. if (Parse (url, out objectURI) == null)
  82. return null;
  83. return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
  84. }
  85. public string Parse (string url, out string objectURI)
  86. {
  87. return TcpChannel.ParseChannelUrl (url, out objectURI);
  88. }
  89. }
  90. }