TcpClientChannel.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.Runtime.Remoting.Channels.Simple;
  15. using System.Threading;
  16. namespace System.Runtime.Remoting.Channels.Tcp
  17. {
  18. public class TcpClientChannel : IChannelSender, IChannel
  19. {
  20. int priority = 1;
  21. string name = "tcp";
  22. IClientChannelSinkProvider _sinkProvider;
  23. public TcpClientChannel ()
  24. {
  25. }
  26. public TcpClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
  27. {
  28. priority = 1;
  29. if (_sinkProvider != null)
  30. {
  31. _sinkProvider = sinkProvider;
  32. // add the tcp provider at the end of the chain
  33. IClientChannelSinkProvider prov = sinkProvider;
  34. while (prov.Next != null) prov = prov.Next;
  35. prov.Next = new TcpClientTransportSinkProvider ();
  36. // Note: a default formatter is added only when
  37. // no sink providers are specified in the config file.
  38. }
  39. else
  40. {
  41. // FIXME: change soap to binary
  42. _sinkProvider = new SimpleClientFormatterSinkProvider ();
  43. _sinkProvider.Next = new TcpClientTransportSinkProvider ();
  44. }
  45. }
  46. public TcpClientChannel (string name, IClientChannelSinkProvider sinkProvider)
  47. {
  48. priority = 1;
  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)
  75. url = ds.ChannelUris [0];
  76. }
  77. if (Parse (url, out objectURI) == null)
  78. return null;
  79. return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
  80. }
  81. public string Parse (string url, out string objectURI)
  82. {
  83. return TcpChannel.ParseChannelUrl (url, out objectURI);
  84. }
  85. }
  86. }