ALPN or Application Layer Protocol Name is a TLS extension that includes the protocol negotiation within the exchange of hello messages. ALPN is able to negotiate which protocol should be handled over a secure connection in a way that is more efficient and avoids additional round trips. The ever-growing in popularity HTTP/2 protocol, makes use of ALPN to further decrease website load times and encrypt connections faster.

According to the RFC 7301 specification, with ALPN the client will send a list of supported application protocols to the server as part of the TLS ClientHello message. The server then selects a protocol and sends back that protocol in its ServerHello message. The application protocol negotiation can therefore be accomplished over one single round trip within the TLS handshake. This method also allows the server to associate a different certificate with each application protocol.

From sgcWebSockets 4.3.2, if you compile sgcWebSockets with our custom Indy library you can make use of ALPN protocol. Indy by default doesn't implements this protocol.

Client 

Create a new websocket client which requires "h2" for ALPN, check after connects which protocol has server accepted.

oClient := TsgcWebSocketClient.Create(nil);
oClient.Host := '127.0.0.1';
oClient.Port := 443;
oClient.TLS := True;
oClient.TLSOptions.ALPNProtocols.Add('h2');
oClient.Active := True;

procedure OnClientConnect(Connection: TsgcWSConnection);
var
  vProtocol: string;
begin
  vProtocol := TsgcWSConnectionClient(Connection).ALPNProtocol;
end; 

Server

 Create a new websocket client which checks if client supports "h2" ALPN connections.

oServer := TsgcWebSocketServer.Create(nil);
oServer.Port := 443;
oServer.SSL := True;
oServer.Active := True;

procedure OnServerSSLALPNSelect(Sender: TObject; aProtocols: TStringList; var aProtocol: string);
begin
  if aProtocols.IndexOf('h2') > -1 then
    aProtocol := 'h2';
end;