次の方法で共有


Socket.SetSocketOption メソッド (SocketOptionLevel, SocketOptionName, Byte[])

指定した Socket オプションを、指定した値に設定します。この値はバイト配列で表されます。

Overloads Public Sub SetSocketOption( _
   ByVal optionLevel As SocketOptionLevel, _   ByVal optionName As SocketOptionName, _   ByVal optionValue() As Byte _)
[C#]
public void SetSocketOption(SocketOptionLeveloptionLevel,SocketOptionNameoptionName,byte[] optionValue);
[C++]
public: void SetSocketOption(SocketOptionLeveloptionLevel,SocketOptionNameoptionName,unsigned charoptionValue __gc[]);
[JScript]
public function SetSocketOption(
   optionLevel : SocketOptionLevel,optionName : SocketOptionName,optionValue : Byte[]);

パラメータ

例外

例外の種類 条件
SocketException ソケットへのアクセスを試みているときにエラーが発生しました。詳細については、「解説」を参照してください。
ObjectDisposedException Socket は閉じられています。

解説

Socket オプションは、現在の Socket の動作を決定します。このオーバーロードを使用して、オプション値としてバイト配列を必要とする Socket オプションを設定します。

メモ    SocketException が発生した場合は、 SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのマニュアルから、エラーの詳細情報を確認できます。これは MSDN から入手できます。

Windows 98, Windows NT 4.0 プラットフォームに関する注意点: optionName パラメータとして AddMembership を使用する前に、 Bind メソッドを呼び出す必要があります。

使用例

[Visual Basic, C#, C++] LingerOption タイムアウト値と Send タイムアウト値を設定する例を次に示します。

 
'Send operations will time-out if confirmation is 
' not received within 1000 milliseconds.
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000)

' The socket will linger for 10 seconds after Socket.Close is called.
Dim lingerOption As New LingerOption(True, 10)
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption)


[C#] 
// Send operations will time-out if confirmation 
// is not received within 1000 milliseconds.
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);

// The socket will linger for 10 seconds after Socket.Close is called.
LingerOption lingerOption = new LingerOption (true, 10);

s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);


[C++] 
// Specifies that send operations will time-out 
// if confirmation is not received within 1000 milliseconds.
s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::SendTimeout, 1000);

// Specifies that the Socket will linger for 10 seconds after Close is called.
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 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Socket クラス | Socket メンバ | System.Net.Sockets 名前空間 | Socket.SetSocketOption オーバーロードの一覧 | SocketOptionName | SocketOptionLevel | GetSocketOption