TcpChannel Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe TcpChannel.
Surcharges
| Nom | Description |
|---|---|
| TcpChannel() |
Initialise une nouvelle instance de la TcpChannel classe, activant uniquement un canal client et non un canal serveur. |
| TcpChannel(Int32) |
Initialise une nouvelle instance de la TcpChannel classe avec un canal de serveur qui écoute sur le port spécifié. |
| TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider) |
Initialise une nouvelle instance de la TcpChannel classe avec les propriétés et récepteurs de configuration spécifiés. |
TcpChannel()
Initialise une nouvelle instance de la TcpChannel classe, activant uniquement un canal client et non un canal serveur.
public:
TcpChannel();
public TcpChannel();
Public Sub New ()
Exemples
L’exemple de code suivant montre comment utiliser ce constructeur.
// Create the channel.
TcpChannel^ clientChannel = gcnew TcpChannel();
// Create the channel.
TcpChannel clientChannel = new TcpChannel();
Remarques
Le constructeur sans paramètre initialise tous les champs à leurs valeurs par défaut. Si le constructeur sans paramètre est utilisé, le canal fonctionne uniquement en tant que canal client et n’écoute aucun port.
S’applique à
TcpChannel(Int32)
Initialise une nouvelle instance de la TcpChannel classe avec un canal de serveur qui écoute sur le port spécifié.
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)
Paramètres
- port
- Int32
Port sur lequel le canal serveur écoute.
Exemples
L’exemple de code suivant illustre l’utilisation de cette méthode. Pour demander qu’un port disponible soit attribué dynamiquement, définissez le port paramètre sur zéro.
// 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()
Remarques
Pour demander que le système de communication à distance choisisse un port ouvert en votre nom, spécifiez le port 0 (zéro). Cela crée une TcpServerChannel instance pour écouter les demandes sur le port attribué dynamiquement. Cette opération est généralement effectuée sur le client pour s’assurer qu’une TcpServerChannel méthode de rappel est à l’écoute.
Si 0 est passé au constructeur, il TcpChannel est instancié pour utiliser un port libre.
S’applique à
TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)
Initialise une nouvelle instance de la TcpChannel classe avec les propriétés et récepteurs de configuration spécifiés.
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)
Paramètres
- properties
- IDictionary
Collection IDictionary qui spécifie les valeurs des propriétés de configuration à utiliser par les canaux client et serveur.
- clientSinkProvider
- IClientChannelSinkProvider
Implémentation IClientChannelSinkProvider à utiliser par le canal client.
- serverSinkProvider
- IServerChannelSinkProvider
Implémentation IServerChannelSinkProvider à utiliser par le canal de serveur.
Exceptions
Une propriété de canal fournie a été mal mise en forme.
Exemples
L’exemple de code suivant montre comment utiliser ce constructeur.
// 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);
Remarques
Les récepteurs de canal fournissent un point de plug-in qui permet d’accéder aux messages sous-jacents qui transitent par le canal, ainsi que le flux utilisé par le mécanisme de transport pour envoyer des messages à un objet distant. Les récepteurs de canal sont également responsables du transport des messages entre le client et le serveur. Les récepteurs de canal sont liés dans une chaîne, et tous les messages de canal transitent par cette chaîne de récepteurs avant que le message soit finalement sérialisé et transporté. Si vous n’avez pas besoin de fonctionnalités de récepteur, définissez les paramètres et serverSinkProvider les clientSinkProvider paramètres nullsur .