SslApplicationProtocol 構造体

定義

TLS アプリケーション プロトコルの値を表します。

public value class SslApplicationProtocol : IEquatable<System::Net::Security::SslApplicationProtocol>
public readonly struct SslApplicationProtocol : IEquatable<System.Net.Security.SslApplicationProtocol>
type SslApplicationProtocol = struct
Public Structure SslApplicationProtocol
Implements IEquatable(Of SslApplicationProtocol)
継承
SslApplicationProtocol
実装

次のコード例は、 SslStreamでのアプリケーション レベルプロトコルのネゴシエーションを示しています。 サーバーは、 protocol1protocol2のサポートをアドバタイズします。 クライアントは、 protocol2protocol3のサポートをアドバタイズします。 一般的にサポートされるプロトコル (protocol2) は、ハンドシェイク中にネゴシエートされます。

async Task Server(NetworkStream stream, X509Certificate2 serverCertificate)
{
    using var server = new SslStream(stream);

    await server.AuthenticateAsServerAsync(new SslServerAuthenticationOptions
    {
        ServerCertificate = serverCertificate,
        ApplicationProtocols = new()
        {
            new("protocol1"),
            new("protocol2"),
        }
    });

    string protocol = Encoding.ASCII.GetString(server.NegotiatedApplicationProtocol.Protocol.Span);
    System.Console.WriteLine($"Server - negotiated protocol: {protocol}");
}

async Task Client(NetworkStream stream, string hostName)
{
    using var client = new SslStream(stream);

    await client.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
    {
        // the host name must match the name on the certificate used on the server side
        TargetHost = hostName,
        ApplicationProtocols = new()
        {
            new("protocol2"),
            new("protocol3")
        }
    });

    string protocol = Encoding.ASCII.GetString(client.NegotiatedApplicationProtocol.Protocol.Span);
    System.Console.WriteLine($"Client - negotiated protocol: {protocol}");
}

// possible output:
//   Server - negotiated protocol: protocol2
//   Client - negotiated protocol: protocol2
Async Function Server(stream As NetworkStream, serverCertificate As X509Certificate2) As Task
    Using serverStream As SslStream = new SslStream(stream)
        Dim options as New SslServerAuthenticationOptions() With
        {
            .ServerCertificate = serverCertificate,
            .ApplicationProtocols = New List(Of SslApplicationProtocol) From
            {
                New SslApplicationProtocol("protocol1"),
                New SslApplicationProtocol("protocol2")
            }
        }
        Await serverStream.AuthenticateAsServerAsync(options)

        Dim protocol As String = Encoding.ASCII.GetString(
            serverStream.NegotiatedApplicationProtocol.Protocol.Span)
        System.Console.WriteLine($"Server - negotiated protocol: {protocol}")
    End Using
End Function

Async Function Client(stream As NetworkStream, hostName As String ) As Task
    Using clientStream As SslStream = new SslStream(stream)
        Dim options as New SslClientAuthenticationOptions() With
        {
            .TargetHost = hostName,
            .ApplicationProtocols = New List(Of SslApplicationProtocol) From
            {
                New SslApplicationProtocol("protocol2"),
                New SslApplicationProtocol("protocol3")
            }
        }
        Await clientStream.AuthenticateAsClientAsync(options)

        Dim protocol As String = Encoding.ASCII.GetString(
            clientStream.NegotiatedApplicationProtocol.Protocol.Span)
        System.Console.WriteLine($"Client - negotiated protocol: {protocol}")
    End Using
End Function

' possible output:
'   Server - negotiated protocol: protocol2
'   Client - negotiated protocol: protocol2

注釈

この型には、HTTP バージョンの定義済みの SslApplicationProtocol 値を持つ静的フィールドが含まれています。

ハンドシェイク中、クライアントは使用可能な ALPN プロトコルの一覧を送信し、サーバーはその一覧から最適な一致を選択します。

サポートされているプロトコルの完全な一覧については、 TLS Application-Layer プロトコル ネゴシエーション (ALPN) プロトコル ID に関するページを参照してください。

コンストラクター

名前 説明
SslApplicationProtocol(Byte[])

SslApplicationProtocolの新しいインスタンスを初期化します。

SslApplicationProtocol(String)

SslApplicationProtocolの新しいインスタンスを初期化します。

フィールド

名前 説明
Http11

HTTP/1.1 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。

Http2

HTTP/2 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。

プロパティ

名前 説明
Protocol

この SslApplicationProtocolによって表される現在の TLS アプリケーション プロトコルを取得します。

メソッド

名前 説明
Equals(Object)

指定したオブジェクトと SslApplicationProtocol を比較します。

Equals(SslApplicationProtocol)

指定したSslApplicationProtocol インスタンスとSslApplicationProtocolを比較します。

GetHashCode()

SslApplicationProtocol インスタンスのハッシュ コードを返します。

ToString()

ToString() メソッドをオーバーライドします。

演算子

名前 説明
Equality(SslApplicationProtocol, SslApplicationProtocol)

2 つの SslApplicationProtocol オブジェクトを比較するための等値演算子。

Inequality(SslApplicationProtocol, SslApplicationProtocol)

2 つの SslApplicationProtocol オブジェクトを比較するための不等値演算子。

適用対象