blob: 39421fab4dc75c3af5a6bf92433d1dd197ba4484 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;26.&nbsp;WebSocket Introduction</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="jetty-dev-guide.html" title="Part&nbsp;IV.&nbsp;Jetty Development Guide"><link rel="prev" href="jetty-handlers.html" title="Chapter&nbsp;25.&nbsp;Handlers"><link rel="next" href="ws-intro-api.html" title="WebSocket APIs"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.4.28-SNAPSHOT</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;26.&nbsp;WebSocket Introduction</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jetty-handlers.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;IV.&nbsp;Jetty Development Guide<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ws-intro-api.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development
</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="websocket-intro"></a>Chapter&nbsp;26.&nbsp;WebSocket Introduction</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="websocket-intro.html#ws-intro-provides">What Jetty provides</a></span></dt><dt><span class="section"><a href="ws-intro-api.html">WebSocket APIs</a></span></dt><dt><span class="section"><a href="_enabling_websocket.html">Enabling WebSocket</a></span></dt></dl></div><p>WebSocket is a new protocol for bidirectional communications initiated via HTTP/1.1 upgrade and providing basic message framing, layered over TCP.
It is based on a low-level framing protocol that delivers messages in either UTF-8 TEXT or BINARY format.</p><p>A single message in WebSocket can be of any size (the underlying framing however does have a single frame limit of <a class="link" href="http://en.wikipedia.org/wiki/9223372036854775807" target="_top">63-bits</a>).
There can be an unlimited number of messages sent.
Messages are sent sequentially, the base protocol does not support interleaved messages.</p><p>A WebSocket connection goes through some basic state changes:</p><div class="table"><a name="d0e26194"></a><p class="title"><b>Table&nbsp;26.1.&nbsp;WebSocket connection states</b></p><div class="table-contents"><table class="table" summary="WebSocket connection states" border="1" width="50%"><colgroup><col class="col_1"><col class="col_2"></colgroup><thead><tr><th align="left" valign="top">State</th><th align="left" valign="top">Description</th></tr></thead><tbody><tr><td align="left" valign="top"><p>CONNECTING</p></td><td align="left" valign="top"><p>A HTTP Upgrade to WebSocket is in progress</p></td></tr><tr><td align="left" valign="top"><p>OPEN</p></td><td align="left" valign="top"><p>The HTTP Upgrade succeeded and the socket is now open and ready to read / write</p></td></tr><tr><td align="left" valign="top"><p>CLOSING</p></td><td align="left" valign="top"><p>A WebSocket Close Handshake has been started</p></td></tr><tr><td align="left" valign="top"><p>CLOSED</p></td><td align="left" valign="top"><p>WebSocket is now closed, no more read/write possible</p></td></tr></tbody></table></div></div><br class="table-break"><p>When a WebSocket is closed, a <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/websocket/api/StatusCode.html" target="_top">status code</a> and short reason string is provided.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ws-intro-provides"></a>What Jetty provides</h2></div></div></div><p>Jetty provides an implementation of the following standards and specs.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><a class="link" href="http://tools.ietf.org/html/rfc6455" target="_top">RFC-6455</a></span></dt><dd><p class="simpara">The WebSocket Protocol</p><p class="simpara">We support the version 13 of the released and final spec.</p><p class="simpara">Jetty tests its WebSocket protocol implementation using the <a class="link" href="http://autobahn.ws/testsuite" target="_top">autobahn testsuite</a>.</p></dd></dl></div><div class="blockquote"><blockquote class="blockquote"><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-plus" aria-hidden="true"></i> Important</h3><p>The early drafts of WebSocket were supported in Jetty 7 and Jetty 8, but this support has been removed in Jetty 9.
This means that Jetty 9 will not support the old browsers that implemented the early drafts of WebSocket. (such as Safari 5.0 or Opera 12)</p></div></blockquote></div><div class="blockquote"><blockquote class="blockquote"><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-lightbulb-o" aria-hidden="true"></i> Tip</h3><p>Want to know if the browser you are targeting supports WebSocket?
Use <a class="link" href="http://caniuse.com/websockets" target="_top">caniuse.com/websockets</a> to find out.</p></div></blockquote></div><div class="variablelist"><dl class="variablelist"><dt><span class="term"><a class="link" href="http://www.jcp.org/en/jsr/detail?id=356" target="_top">JSR-356</a></span></dt><dd><p class="simpara">The Java WebSocket API (<code class="literal">javax.websocket</code>)</p><p class="simpara">This is the official Java API for working with WebSockets.</p></dd></dl></div><p>Unstable standards and specs:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><a class="link" href="https://datatracker.ietf.org/doc/draft-ietf-hybi-websocket-perframe-compression/" target="_top">perframe-compression</a></span></dt><dd><p class="simpara">Per Frame Compression Extension.</p><p class="simpara">An early extension draft from the Google/Chromium team that would provide WebSocket frame compression.
perframe-compression using deflate algorithm is present on many versions of Chrome/Chromium.</p><p class="simpara">Jetty&#8217;s support for perframe-compression is based on the draft-04 spec.
This standard is being replaced with permessage-compression.</p></dd><dt><span class="term"><a class="link" href="https://datatracker.ietf.org/doc/draft-tyoshino-hybi-permessage-compression/" target="_top">permessage-compression</a></span></dt><dd><p class="simpara">Per Frame Compression Extension.</p><p class="simpara">This is the replacement for perframe-compression, switching the compression to being based on the entire message, not the individual frames.</p></dd></dl></div></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jetty-handlers.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jetty-dev-guide.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ws-intro-api.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;25.&nbsp;Handlers&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;WebSocket APIs</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>