TcpChannel Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da TcpChannel classe.
Sobrecargas
| Name | Descrição |
|---|---|
| TcpChannel() |
Inicializa uma nova instância da TcpChannel classe, ativando apenas um canal cliente, e não um canal servidor. |
| TcpChannel(Int32) |
Inicializa uma nova instância da TcpChannel classe com um canal de servidor que escuta na porta especificada. |
| TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider) |
Inicializa uma nova instância da TcpChannel classe com as propriedades de configuração especificadas e faz sinks. |
TcpChannel()
Inicializa uma nova instância da TcpChannel classe, ativando apenas um canal cliente, e não um canal servidor.
public:
TcpChannel();
public TcpChannel();
Public Sub New ()
Exemplos
O seguinte exemplo de código mostra como usar este construtor.
// Create the channel.
TcpChannel^ clientChannel = gcnew TcpChannel();
// Create the channel.
TcpChannel clientChannel = new TcpChannel();
Observações
O construtor sem parâmetros inicializa todos os campos aos seus valores predefinidos. Se for usado o construtor sem parâmetros, o canal funciona apenas como canal cliente e não escuta em nenhuma porta.
Aplica-se a
TcpChannel(Int32)
Inicializa uma nova instância da TcpChannel classe com um canal de servidor que escuta na porta especificada.
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)
Parâmetros
- port
- Int32
A porta onde o canal do servidor escuta.
Exemplos
O exemplo de código seguinte demonstra o uso deste método. Para pedir que uma porta disponível seja atribuída dinamicamente, defina o port parâmetro a 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()
Observações
Para solicitar que o sistema remoto escolha uma porta aberta em seu nome, especifique a porta 0 (zero). Isto criará uma TcpServerChannel instância para ouvir pedidos na porta atribuída dinamicamente. Isto é normalmente feito no cliente para garantir que está TcpServerChannel a ouvir os métodos de retorno.
Se 0 for passado ao construtor, é TcpChannel instanciado para usar uma porta livre.
Aplica-se a
TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)
Inicializa uma nova instância da TcpChannel classe com as propriedades de configuração especificadas e faz 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)
Parâmetros
- properties
- IDictionary
Uma IDictionary coleção que especifica valores para propriedades de configuração a serem usadas pelos canais cliente e servidor.
- clientSinkProvider
- IClientChannelSinkProvider
A IClientChannelSinkProvider implementação a ser usada pelo canal cliente.
- serverSinkProvider
- IServerChannelSinkProvider
A IServerChannelSinkProvider implementação a ser usada pelo canal do servidor.
Exceções
Uma propriedade de canal fornecida estava mal formatada.
Exemplos
O seguinte exemplo de código mostra como usar este construtor.
// 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);
Observações
Para mais informações sobre as propriedades de configuração do canal, consulte Propriedades de Configuração de Canal e Formator.
Os sumidouros de canal fornecem um ponto plug-in que permite o acesso às mensagens subjacentes que fluem pelo canal, bem como ao fluxo usado pelo mecanismo de transporte para enviar mensagens para um objeto remoto. Os dissipadores de canal também são responsáveis por transportar mensagens entre o cliente e o servidor. Os sumidouros de canal estão ligados numa cadeia, e todas as mensagens de canal fluem por esta cadeia de sumidouros antes de a mensagem ser finalmente serializada e transportada. Se não precisares de funcionalidade de sink, define os clientSinkProvider parâmetros and serverSinkProvider para null.