ALPN

Supported by

 

  TsgcWebSocketServer

  TsgcWebSocketHTTPServer

  TsgcWebSocketClient

 

 

Application-Layer Protocol Negotiation (ALPN) is a Transport Layer Security (TLS) extension for application-layer protocol negotiation. ALPN allows the application layer to negotiate which protocol should be performed over a secure connection in a manner that avoids additional round trips and which is independent of the application-layer protocols. It is needed by secure HTTP/2 connections, which improves the compresslion of web pages and reduces their latency compared to HTTP/1.x.

 

Client

You can configure in TLSOptions.ALPNProtocols, which protocols are supported by client. When client connects to server, these protocols are sent on the initial TLS handshake 'Client Hello', and it lists the protocols that the client supports, and server select which protocol will be used, if any.

 

You can get which protocol has been selected by server accessing to ALPNProtocol property of TsgcWSConnectionClient.

 

Server

When there is a new TLS connection, OnSSLALPNSelect event is called, here you can access to a list of protocols which are supported by client and server can select which of them is supported.

 

 

If there is no support for any protocol, aProtocol can be left empty.

 


// Client
void OnClientConnect(TsgcWSConnection Connection)
{
  string vProtocol = (TsgcWSConnectionClient)(Connection).ALPNProtocol;
}
  
// Server
void OnSSLALPNSelect(string Protocols, ref string Protocol)
{
  if (Array.IndexOf(Protocols.Split(','), "h2") >= 0) 
  {
    Protocol = 'h2';
  }
}