TcpClientChannel.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. priority = 1;
  28. if (sinkProvider != null)
  29. {
  30. _sinkProvider = sinkProvider;
  31. // add the tcp provider at the end of the chain
  32. IClientChannelSinkProvider prov = sinkProvider;
  33. while (prov.Next != null) prov = prov.Next;
  34. prov.Next = new TcpClientTransportSinkProvider ();
  35. // Note: a default formatter is added only when
  36. // no sink providers are specified in the config file.
  37. }
  38. else
  39. {
  40. _sinkProvider = new BinaryClientFormatterSinkProvider ();
  41. _sinkProvider.Next = new TcpClientTransportSinkProvider ();
  42. }
  43. }
  44. public TcpClientChannel (string name, IClientChannelSinkProvider sinkProvider)
  45. {
  46. priority = 1;
  47. this.name = name;
  48. _sinkProvider = sinkProvider;
  49. // add the tcp provider at the end of the chain
  50. IClientChannelSinkProvider prov = sinkProvider;
  51. while (prov.Next != null) prov = prov.Next;
  52. prov.Next = new TcpClientTransportSinkProvider ();
  53. }
  54. public string ChannelName
  55. {
  56. get {
  57. return name;
  58. }
  59. }
  60. public int ChannelPriority
  61. {
  62. get {
  63. return priority;
  64. }
  65. }
  66. public IMessageSink CreateMessageSink (string url,
  67. object remoteChannelData,
  68. out string objectURI)
  69. {
  70. if (url == null && remoteChannelData != null) {
  71. IChannelDataStore ds = remoteChannelData as IChannelDataStore;
  72. if (ds != null && ds.ChannelUris.Length > 0)
  73. url = ds.ChannelUris [0];
  74. else {
  75. objectURI = null;
  76. return null;
  77. }
  78. }
  79. if (Parse (url, out objectURI) == null)
  80. return null;
  81. return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
  82. }
  83. public string Parse (string url, out string objectURI)
  84. {
  85. return TcpChannel.ParseChannelUrl (url, out objectURI);
  86. }
  87. }
  88. }