Wbsocket Official agreement content: Http://datatracker.ietf.org/doc/rfc6455/?include_text=1
Connection Request Content:
get/http/1.1 Connection:upgrade host:127.0.0.1:8088 origin:null sec-websocket-extensions:x-webkit-deflate-frame sec-websocket-key:puvouwb7rel6z2avzbknfw== sec-websocket-version:13 Upgrade:websocket
When the server receives the request, it mainly becomes the key for Sec-websocket-key generation pair sec-websocket-accept, and the sec-websocket-accept value is simpler SHA1 ( SEC-WEBSOCKET-KEY+258EAFA5-E914-47DA-95CA-C5AB0DC85B11) can
http/1.1 switching Protocols connection:upgrade server:beetle websocket Server upgrade:websocket Date:mon, Nov 2012 23:42:44 GMT access-control-allow-credentials:true access-control-allow-headers:content-type Sec-WebSocket-Accept: fckgur8c7osdslfejtwrjw6wo8q=
Websocket-api.jar is integrated in Tomcat8. His encapsulation of the WebSocket protocol:
Package com.lgy.websocket;
Import java.io.IOException;
Import Java.util.Set;
Import Java.util.concurrent.CopyOnWriteArraySet;
Import Java.util.concurrent.atomic.AtomicInteger;
Import Javax.websocket.OnClose;
Import Javax.websocket.OnError;
Import Javax.websocket.OnMessage;
Import Javax.websocket.OnOpen;
Import javax.websocket.Session;
Import Javax.websocket.server.ServerEndpoint; @ServerEndpoint (value = "/websocket/chat") public class Hellowebsocketservlet {//private static final log = Logfact
Ory.getlog (Chatannotation.class);
private static final String Guest_prefix = "GUEST";
private static final Atomicinteger Connectionids = new Atomicinteger (0);
Private static final set