2 // System.Runtime.Remoting.Channels.Tcp.TcpClientChannel.cs
4 // Author: Dietmar Maurer (dietmar@ximian.com)
5 // Lluis Sanchez Gual (lluis@ideary.com)
7 // 2002 (C) Copyright, Ximian, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
33 using System.Net.Sockets;
34 using System.Runtime.Remoting.Messaging;
35 using System.Runtime.Remoting.Channels;
36 using System.Threading;
38 namespace System.Runtime.Remoting.Channels.Tcp
40 public class TcpClientChannel : IChannelSender, IChannel
44 IClientChannelSinkProvider _sinkProvider;
46 public TcpClientChannel ()
48 _sinkProvider = new BinaryClientFormatterSinkProvider ();
49 _sinkProvider.Next = new TcpClientTransportSinkProvider ();
52 public TcpClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
54 object val = properties ["name"];
55 if (val != null) name = val as string;
57 val = properties ["priority"];
58 if (val != null) priority = Convert.ToInt32 (val);
60 if (sinkProvider != null)
62 _sinkProvider = sinkProvider;
64 // add the tcp provider at the end of the chain
65 IClientChannelSinkProvider prov = sinkProvider;
66 while (prov.Next != null) prov = prov.Next;
67 prov.Next = new TcpClientTransportSinkProvider ();
69 // Note: a default formatter is added only when
70 // no sink providers are specified in the config file.
74 _sinkProvider = new BinaryClientFormatterSinkProvider ();
75 _sinkProvider.Next = new TcpClientTransportSinkProvider ();
80 public TcpClientChannel (string name, IClientChannelSinkProvider sinkProvider)
83 _sinkProvider = sinkProvider;
85 // add the tcp provider at the end of the chain
86 IClientChannelSinkProvider prov = sinkProvider;
87 while (prov.Next != null) prov = prov.Next;
88 prov.Next = new TcpClientTransportSinkProvider ();
91 public string ChannelName
98 public int ChannelPriority
105 public virtual IMessageSink CreateMessageSink (string url,
106 object remoteChannelData,
107 out string objectURI)
109 if (url != null && Parse (url, out objectURI) != null)
110 return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
112 if (remoteChannelData != null) {
113 IChannelDataStore ds = remoteChannelData as IChannelDataStore;
114 if (ds != null && ds.ChannelUris.Length > 0)
115 url = ds.ChannelUris [0];
122 if (Parse (url, out objectURI) == null)
125 return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
128 public string Parse (string url, out string objectURI)
130 return TcpChannel.ParseChannelUrl (url, out objectURI);