Java Authoring WebSocket Service side

Source: Internet
Author: User
Tags throwable

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 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.