[27] [DFN[[RUBYB[[[部分プロトコル]]]@en[subprotocol]]]]は、
[[WebSocket]] 上で利用する[[プロトコル]]を表します。

* 仕様書

[REFS[
- [22] [CITE@en[RFC 6455 - The WebSocket Protocol]] ([TIME[2015-03-11 20:42:50 +09:00]] 版) <http://tools.ietf.org/html/rfc6455#section-4>
-- [1] '''[CITE@en[RFC 6455 - The WebSocket Protocol]] ([TIME[2015-03-11 20:42:50 +09:00]] 版) <http://tools.ietf.org/html/rfc6455#section-4.3>'''
- [2] [CITE@en[RFC 6455 - The WebSocket Protocol]] ([TIME[2015-03-11 20:42:50 +09:00]] 版) <http://tools.ietf.org/html/rfc6455#section-11.3.4>
- [4] [CITE@en[RFC 6455 - The WebSocket Protocol]] ([TIME[2015-03-11 20:42:50 +09:00]] 版) <http://tools.ietf.org/html/rfc6455#section-11.5>
- [32] [CITE@en[RFC 7936 - Clarifying Registry Procedures for the WebSocket Subprotocol Name Registry]] ([TIME[2016-07-28 23:25:53 +09:00]]) <https://tools.ietf.org/html/rfc7936>
- [6] [CITE[WebSocket Protocol Registries]] ([TIME[2015-03-06 13:09:47 +09:00]] 版) <https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name>
- [25] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-05-06 10:42:35 +09:00]] 版) <https://html.spec.whatwg.org/#dom-websocket>
- [33] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-05-06 10:42:35 +09:00]] 版) <https://html.spec.whatwg.org/#dom-websocket-protocol>
]REFS]

* 意味

[41] [[WebSocket]] の[[部分プロトコル]]は、
[[WebSocket]] で送受信する[[アプリケーションプロトコル]]を識別するものです。

[42] 1つの [[WebSocket]] [[エンドポイント]]で複数のプロトコルを扱いたい時に、
相互の区別のために有用かもしれません。
しかしほとんどの用途では特定[[エンドポイント]]では特定のプロトコルしか使わないでしょうから、
この機能が必要となる場面は滅多にありません。

* 構文

[23] [[部分プロトコル]]名は、[[字句]]です [SRC[>>22, >>1]]。

[24] [[RFC]] は、[CODE[[[,]]]] と [CODE(charname)@en[[[SP]]]]
以外の[[ASCII印字可能文字]]であることを要求しつつ、[[ABNF]]
では[[字句]]と定義しています。 [[ABNF]] に従うことや従わないものを拒絶することも
(曖昧に) 求めています。結果としてどのような動作が求められているのかは不明確です。

[26] [[HTML Standard]] は、[[スクリプト]]が指定した値が
「[CODE(HTTP)@en[[[Sec-WebSocket-Protocol:]]]] の要件を満たさないなら」 [SRC[>>25]]
[[例外]]を投げることを求めています。

[40] [[Chrome]] は[[字句]]でない[[文字]]や[[空文字列]]を与えると、
[[例外]]を投げるようです。
[TIME[2018-03-23T11:54:57.800Z]]

* 文脈

[3] [[要求]]では複数使えます。[[応答]]で複数使っては[['''なりません''']]。 [SRC[>>2]]

* [CODE(DOMi)@en[WebSocket]] インターフェイス [CODE(DOMa)@en[protocol]] 属性

[34] [CODE(DOMi)@en[[[WebSocket]]]] [[インターフェイス]]の
[DFN[[CODE(DOMa)@en[[[protocol]]]]]] [[IDL属性]]は、
利用している[[部分プロトコル]]について返すものです。

[35] この[[属性]]は、内部的に保持している値を返さなければ[['''なりません''']] [SRC[>>33]]。
値は、[[WebSocket接続の確立]]の過程で設定されます。

* 部分プロトコルの名前

[20] [[部分プロトコル]]は、[[サーバー]]と[[クライアント]]との合意があれば好きな名前を使って構いません。

[21] しかし広い範囲で使われるものは共通の名前があると便利ということで、
[[部分プロトコル]]名を規定する仕様書も存在しています。

[5] [[部分プロトコル]]の名前には、[[IANA登録簿]]があります [SRC[>>4, >>6]]。

[7] 実際に色々な[[部分プロトコル]]名が登録されているようです。

[36] [[大文字]]と[[小文字]]は、区別されます。

[37] しかし[[大文字]]と[[小文字]]の差しかない名前を [[IANA]] に登録することはできません
[SRC[>>32]]。

;; [29] >>28 に [[JSON]] 形式の一覧データファイルがあります。
[REFS[
- [28] [CITE@en[data-web-defs/http-frames.txt at master · manakai/data-web-defs]] ([TIME[2015-05-28 00:33:14 +09:00]] 版) <https://github.com/manakai/data-web-defs/blob/master/doc/http-frames.txt>
]REFS]

[8] [CITE@en[RFC 7118 - The WebSocket Protocol as a Transport for the Session Initiation Protocol (SIP)]] ([TIME[2015-05-03 17:32:08 +09:00]] 版) <https://tools.ietf.org/html/rfc7118>

[9] 値 [CODE[[[rfb]]]] は [[RFC 6143]] を出典に登録されていますが、
[[RFC 6143]] は [[WebSocket]] に言及しておらず、どのように使うのか不明です。

[14] [CITE@en[draft-garnero-rfb-websocket-00 - The WebSocket Protocol as a Transport for the Remote Framebuffer Protocol (RFB)]] ([TIME[2015-04-24 04:15:56 +09:00]] 版) <https://tools.ietf.org/html/draft-garnero-rfb-websocket-00>

[13] [CITE@en[draft-realvnc-websocket-02 - Use of the WebSocket Protocol as a Transport for the Remote Framebuffer Protocol]] ([TIME[2015-04-24 04:00:37 +09:00]] 版) <https://tools.ietf.org/html/draft-realvnc-websocket-02>

[10] [CITE@en[RFC 7395 - An Extensible Messaging and Presence Protocol (XMPP) Subprotocol for WebSocket]] ([TIME[2015-05-03 18:14:54 +09:00]] 版) <http://tools.ietf.org/html/rfc7395>

[11] [CITE@en[draft-pd-dispatch-msrp-websocket-08 - The WebSocket Protocol as a Transport for the Message Session Relay Protocol (MSRP)]] ([TIME[2015-04-24 04:33:44 +09:00]] 版) <https://tools.ietf.org/html/draft-pd-dispatch-msrp-websocket-08>

[12] [CITE@en[draft-ietf-bfcpbis-bfcp-websocket-04 - The WebSocket Protocol as a Transport for the Binary Floor Control Protocol (BFCP)]] ([TIME[2015-04-24 04:36:11 +09:00]] 版) <https://tools.ietf.org/html/draft-ietf-bfcpbis-bfcp-websocket-04>

[15] [CITE@en[draft-hapner-hybi-messagebroker-subprotocol-03 - The MessageBroker WebSocket Subprotocol]] ([TIME[2015-04-24 04:15:30 +09:00]] 版) <https://tools.ietf.org/html/draft-hapner-hybi-messagebroker-subprotocol-03>

[16] [CITE@en[draft-iijima-netconf-websocket-ps-04 - NETCONF over WebSocket]] ([TIME[2015-04-24 04:39:19 +09:00]] 版) <https://tools.ietf.org/html/draft-iijima-netconf-websocket-ps-04>

[17] [CITE@en[draft-chenxin-behave-turn-websocket-01 - WebSocket Protocol as a Transport for Traversal Using Relays around NAT (TURN)]] ([TIME[2015-04-24 04:39:52 +09:00]] 版) <https://tools.ietf.org/html/draft-chenxin-behave-turn-websocket-01>

[18] [CITE@en[draft-savolainen-core-coap-websockets-04 - CoAP over WebSockets]] ([TIME[2015-04-24 04:25:15 +09:00]] 版) <https://tools.ietf.org/html/draft-savolainen-core-coap-websockets-04>

[FIG(quote)[
[FIGCAPTION[
[19] [CITE@en-US[Writing WebSocket servers - WebSockets | MDN]]
([TIME[2015-03-07 20:59:19 +09:00]] 版)
<https://developer.mozilla.org/en-US/docs/WebSockets/Writing_WebSocket_servers>
]FIGCAPTION]

> To avoid name conflict, it's recommended to make your subprotocol name part of a domain string. If you are building a custom chat app that uses a proprietary format exclusive to Example Inc., then you might use this: Sec-WebSocket-Protocol: chat.example.com. For different versions, a widely-used method is to add a / followed by the version number, like chat.example.com/2.0. Note that this isn't required, it's just an optional convention, and you can use any string you wish.

]FIG]

[30] [CITE@en[Define the WebSocket subprotocol check as part of response validation · whatwg/fetch@08f8560]]
([TIME[2016-03-17 00:54:09 +09:00]] 版)
<https://github.com/whatwg/fetch/commit/08f8560f6cecaedc1c3372f9fff1ee39c3bfc86f>

[31] [CITE@en[Define permessage-deflate extension and cache-mode for WebSocket · whatwg/fetch@267a8ef]]
([TIME[2016-03-17 00:54:37 +09:00]] 版)
<https://github.com/whatwg/fetch/commit/267a8effeacfe5d641010d1d4f4609f9602cdab6>

[38] [CITE@en[RFC 7977 - The WebSocket Protocol as a Transport for the Message Session Relay Protocol (MSRP)]]
([TIME[2016-10-04 23:50:28 +09:00]])
<https://tools.ietf.org/html/rfc7977>

[39] [CODE[msg.nicovideo.jp#json]]