語言

TcpChannel 建構函式

定義

初始化 TcpChannel 類別的新執行個體。

多載

名稱 Description
TcpChannel()

初始化該類別的新實例 TcpChannel ,僅啟用用戶端通道,而非伺服器通道。

TcpChannel(Int32)

初始化一個新的類別實例 TcpChannel ,並以伺服器通道監聽指定的埠口。

TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

初始化一個具有指定配置屬性與匯入的類別新實例 TcpChannel 。

TcpChannel()

初始化該類別的新實例 TcpChannel ,僅啟用用戶端通道,而非伺服器通道。

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

範例

以下程式碼範例說明如何使用此建構子。

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

備註

無參數建構子會將所有欄位初始化為預設值。 若使用無參數建構器,該通道僅作為用戶端通道運作,且不會監聽任何埠口。

適用於

TcpChannel(Int32)

初始化一個新的類別實例 TcpChannel ,並以伺服器通道監聽指定的埠口。

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)

參數

port
Int32

伺服器通道監聽的埠口。

範例

以下程式碼範例示範使用此方法。 若要請求動態分配可用埠口,請將參數設 port 為零。

// 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()

備註

若要請求遠端系統代表你選擇開啟的埠口,請指定埠口 0(零)。 這會建立 TcpServerChannel 一個實例來監聽動態分配埠上的請求。 這通常是在用戶端執行,以確保 a TcpServerChannel 正在監聽回調方法。

若將 0 傳遞給建構子,則 TcpChannel 實例化為使用空門埠。

適用於

TcpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

初始化一個具有指定配置屬性與匯入的類別新實例 TcpChannel 。

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)

參數

properties
IDictionary

一個 IDictionary 集合,指定客戶端與伺服器通道所使用的設定屬性值。

clientSinkProvider
IClientChannelSinkProvider

客戶 IClientChannelSinkProvider 端通道將使用的實作。

serverSinkProvider
IServerChannelSinkProvider

伺服器 IServerChannelSinkProvider 通道將使用的實作。

例外狀況

提供的頻道屬性格式不正確。

範例

以下程式碼範例說明如何使用此建構子。

// 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);

備註

欲了解更多通道配置屬性,請參閱 通道與形式配置屬性。

通道匯提供一個外掛點,允許存取通道中流經的底層訊息,以及傳輸機制用來向遠端物件傳送訊息的串流。 通道匯也負責在用戶端與伺服器間傳送訊息。 通道匯以鏈條相連,所有通道訊息在訊息最終序列化並傳輸前都會經過這條匯鏈。 如果你不需要匯入功能,請將 and clientSinkProvider 參數設serverSinkProvider為 null。

另請參閱

適用於