title: Jetty 9 WebSocket Server Max Message Size on Session
body: <p>I ran into this issue and had some difficulty finding answers for this anywhere so I thought I would enter it here for future programmers.</p>
  
  <p>In Jetty 9, if you try to set the maximum message size on a session object to handle large data packets, it will not work.  You will still get disconnected if your client tries to send large data. I'm talking about setMaximimumMessageSize on this object: <a href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/Session.html" rel="noreferrer">http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/Session.html</a></p>
  
  <p>Instead, what you have to do is set the max message size on the policy object acquired from the WebSocketServletFactory.</p>
  
  <pre class="lang-java prettyprint-override"><code>public final class MyWebSocketServlet extends WebSocketServlet
  {
      private static final long MAX_MESSAGE_SIZE = 1000000;
  
      @Override
      public void configure(WebSocketServletFactory factory)
      {
          factory.getPolicy().setMaxMessageSize(MAX_MESSAGE_SIZE);
          factory.setCreator(new MyWebSocketCreator());
      }
  }
  </code></pre>
  
  <p>This will work as intended and your server will be able to handle large messages up to the maximum size you set.</p>