Skip to content

PerMessageDeflateExample

Chen edited this page Jul 28, 2020 · 6 revisions

###Introduction### Enable the extension with reference to both a server and client example as follow: PerMessageDeflateExample

###How does it work### WebSocket Per-Message Compression Extension

Extension Negotiation

###Example### 1.1 DeflateClient:

private static final Draft perMessageDeflateDraft = new Draft_6455(new PerMessageDeflateExtension());  
    private static class DeflateClient extends WebSocketClient { 
        public DeflateClient() throws URISyntaxException {
            super(new URI("ws://localhost:" + PORT), perMessageDeflateDraft);
        }

1.2 DefalteServer:

private static class DeflateServer extends WebSocketServer {
        public DeflateServer() { 
            super(new InetSocketAddress(PORT), Collections.singletonList(perMessageDeflateDraft));
        }