基になるネットワーク Socket を取得します。
Protected ReadOnly Property Server As Socket
[C#]
protected Socket Server {get;}
[C++]
protected: __property Socket* get_Server();
[JScript]
protected function get Server() : Socket;
プロパティ値
基になる Socket 。
解説
TcpListener は受信クライアント接続要求を待機する Socket を作成します。 TcpListener の派生クラスは、このプロパティを使用してこの Socket を取得できます。 TcpListener が提供する以上のアクセスが必要な場合は、 Server プロパティが返した、基になる Socket を使用します。
メモ Server は、受信クライアント接続要求の待機に使用する Socket だけを返します。 AcceptSocket メソッドを使用して保留中の接続要求を受け入れ、データの送受信のための Socket を取得します。また、 AcceptTcpClient メソッドを使用して保留中の接続要求を受け入れ、データの送受信のための TcpClient を取得することもできます。
使用例
[Visual Basic, C#, C++] 次に示すのは、 TcpListener を継承し、 Server メソッドを実装するクラスの例です。この例では、基になる Socket が取得され、 Linger Socket オプションは、接続の終了後にネットワーク バッファにデータがまだ残っていると、10 秒後にタイムアウトになるよう構成されています。
Imports System
Imports System.Net
Imports System.Net.Sockets
Public Class MyTcpListenerDerivedClass
Inherits TcpListener
Public Sub New(address As IPAddress, port As Integer)
MyBase.New(address, port)
End Sub 'New
Public Sub UsingProtectedMethods()
' The protected property 'Active' determines whether a connection is established.
If Me.Active Then
Dim s As Socket = Me.Server
'Limit socket linger time to 10 seconds.
Dim lingerOption As New LingerOption(True, 10)
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption)
End If
End Sub
End Class
[C#]
using System;
using System.Net;
using System.Net.Sockets;
public class MyTcpListenerDerivedClass : TcpListener
{
public MyTcpListenerDerivedClass(IPAddress address, int port) : base(address, port){}
public void UsingProtectedMethods()
{
// The protected property 'Active' determines whether a connection is established.
if (this.Active)
{
Socket s = this.Server;
// Limit socket linger time to 10 seconds.
LingerOption lingerOption = new LingerOption(true, 10);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
__gc class MyTcpListenerDerivedClass : public TcpListener {
public:
MyTcpListenerDerivedClass(int port) : TcpListener(port) {}
void UsingProtectedMethods() {
// The protected property 'Active' determines whether a connection is established.
if (this->Active)
{
Socket* s = this->Server;
// Limit socket linger time to 10 seconds.
LingerOption* lingerOption = new LingerOption(true, 10);
s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::Linger, lingerOption);
}
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
TcpListener クラス | TcpListener メンバ | System.Net.Sockets 名前空間 | Socket | AcceptSocket | AcceptTcpClient