Edit

Share via


TcpChannel Constructors

Definition

Initializes a new instance of the TcpChannel class.

Overloads

TcpChannel()

Initializes a new instance of the TcpChannel class, activating only a client channel, and not a server channel.

TcpChannel(Int32)

Initializes a new instance of the TcpChannel class with a server channel that listens on the specified port.

TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

Initializes a new instance of the TcpChannel class with the specified configuration properties and sinks.

TcpChannel()

Initializes a new instance of the TcpChannel class, activating only a client channel, and not a server channel.

public:
 TcpChannel();
public TcpChannel ();
Public Sub New ()

Examples

The following code example shows how to use this constructor.

// Create the channel.
TcpChannel^ clientChannel = gcnew TcpChannel();
// Create the channel.
TcpChannel clientChannel = new TcpChannel();

Remarks

The parameterless constructor initializes all fields to their default values. If the parameterless constructor is used, the channel functions only as a client channel, and does not listen on any ports.

Applies to

TcpChannel(Int32)

Initializes a new instance of the TcpChannel class with a server channel that listens on the specified port.

public:
 TcpChannel(int port);
public TcpChannel (int port);
new System.Runtime.Remoting.Channels.Tcp.TcpChannel : int -> System.Runtime.Remoting.Channels.Tcp.TcpChannel
Public Sub New (port As Integer)

Parameters

port
Int32

The port on which the server channel listens.

Examples

The following code example demonstrates using this method. To request that an available port be dynamically assigned, set the port parameter to zero.

// Registers the server and waits until the user hits enter.
TcpChannel^ chan = gcnew TcpChannel( 8084 );
ChannelServices::RegisterChannel( chan );

RemotingConfiguration::RegisterWellKnownServiceType(
   Type::GetType( "HelloServer,server" ),
   "SayHello",
   WellKnownObjectMode::SingleCall );
System::Console::WriteLine( L"Hit <enter> to exit..." );
System::Console::ReadLine();
// Registers the server and waits until the user hits enter.
TcpChannel chan = new TcpChannel(8084);
ChannelServices.RegisterChannel(chan);

RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("HelloServer,server"),
                                                  "SayHello",
                                                   WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit <enter> to exit...");
System.Console.ReadLine();
' Registers the server and waits until the user hits enter.
Dim chan As New TcpChannel(8084)
ChannelServices.RegisterChannel(chan)

RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("HelloServer,server"), "SayHello", WellKnownObjectMode.SingleCall)
System.Console.WriteLine("Hit <enter> to exit...")
System.Console.ReadLine()

Remarks

To request that the remoting system choose an open port on your behalf, specify port 0 (zero). This will create a TcpServerChannel instance to listen for requests on the dynamically assigned port. This is typically done on the client to make sure that a TcpServerChannel is listening for callback methods.

If 0 is passed to the constructor the TcpChannel is instantiated to use a free port.

Applies to

TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

Initializes a new instance of the TcpChannel class with the specified configuration properties and sinks.

public:
 TcpChannel(System::Collections::IDictionary ^ properties, System::Runtime::Remoting::Channels::IClientChannelSinkProvider ^ clientSinkProvider, System::Runtime::Remoting::Channels::IServerChannelSinkProvider ^ serverSinkProvider);
public TcpChannel (System.Collections.IDictionary properties, System.Runtime.Remoting.Channels.IClientChannelSinkProvider clientSinkProvider, System.Runtime.Remoting.Channels.IServerChannelSinkProvider serverSinkProvider);
new System.Runtime.Remoting.Channels.Tcp.TcpChannel : System.Collections.IDictionary * System.Runtime.Remoting.Channels.IClientChannelSinkProvider * System.Runtime.Remoting.Channels.IServerChannelSinkProvider -> System.Runtime.Remoting.Channels.Tcp.TcpChannel
Public Sub New (properties As IDictionary, clientSinkProvider As IClientChannelSinkProvider, serverSinkProvider As IServerChannelSinkProvider)

Parameters

properties
IDictionary

A IDictionary collection that specifies values for configuration properties to be used by the client and server channels.

clientSinkProvider
IClientChannelSinkProvider

The IClientChannelSinkProvider implementation to be used by the client channel.

serverSinkProvider
IServerChannelSinkProvider

The IServerChannelSinkProvider implementation to be used by the server channel.

Exceptions

A provided channel property was improperly formatted.

Examples

The following code example shows how to use this constructor.

// Specify the properties for the server channel.
System::Collections::IDictionary^ dict = gcnew System::Collections::Hashtable;
dict[ "port" ] = 9090;
dict[ "authenticationMode" ] = "IdentifyCallers";

// Set up the server channel.
TcpChannel^ serverChannel = gcnew TcpChannel( dict,nullptr,nullptr );
ChannelServices::RegisterChannel( serverChannel );
// Specify the properties for the server channel.
System.Collections.IDictionary dict =
    new System.Collections.Hashtable();
dict["port"] = 9090;
dict["authenticationMode"] = "IdentifyCallers";

// Set up the server channel.
TcpChannel serverChannel = new TcpChannel(dict, null, null);
ChannelServices.RegisterChannel(serverChannel);

Remarks

For more information about channel configuration properties, see Channel and Formatter Configuration Properties.

Channel sinks provide a plug-in point that allows access to the underlying messages flowing through the channel as well as the stream used by the transport mechanism to send messages to a remote object. Channel sinks are also responsible for transporting messages between the client and the server. Channel sinks are linked together in a chain, and all channel messages flow through this chain of sinks before the message is finally serialized and transported. If you do not require sink functionality, set the clientSinkProvider and serverSinkProvider parameters to null.

See also

Applies to