challenges, there is a difficulty in design considerations.The rest architecture is now a widely accepted, easy-to-understand architecture for building modern Web applications. The rest architecture relies on many URLs, and several HTTP methods, using the principles of linking, keeping stateless, and so on.In contrast, the WebSocket app may use only one URL for the initial HTTP handshake. All subsequent messages share this TCP
WebSocket build tutorial, websocket build
How to build a websocket?
The first step is to compile a simple jsp file, which mainly includes websocket connection and four websocket response events.
Step 2: configure the struts. xml
Sec-websocket-key string provided by the browser, adds a "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" string, And then take the hash value of the sha-1. This value is validated by the browser to prove that the target server did respond to the websocket request. Sec-websocket-location represents the WebSocket URL for the com
) {console.log (evt.data); Ws.close ();};
Ws.onclose = function (evt) {console.log ("websocketclosed!");
Ws.onerror = function (evt) {console.log ("websocketerror!");
This code has only 5 lines in total, and now gives a quick overview of the meaning of these 5 lines of code.
The first line of code is the request for a WebSocket object, which is the address of the server that needs to be connected, as with the HTTP protocol using the http://, the
: communication can only be initiated by the client.For example, we want to understand today's weather, only the client makes a request to the server, and the server returns the query results. The HTTP protocol does not make the server actively push information to the client.The characteristics of this one-way request, doomed if the server has a continuous state change, the client to learn is very troublesome. We can only use polling: every once in a while, we send out a query to see if the serv
. sendSocketMessage ({data: 'stock',})} // receives the wx data. onSocketMessage (function (data) {var objData = JSON. parse (data. data); console. log (data); new wxCharts ({canvasId: 'linecanca', // specify the canvas id Animation: false, type: 'line', // The type is a linear chart categories: ['20170101', '20160301', '20160301', '20160301 ', '000000'], series: [{name: 'transaction volume ', data: objData, // the data format: function (val) received by web
"receive /app/change-notice the value sent, and then forward the value to the /topic/notice client."
/topic/noticeis an address that is specified when the client initiates a connection, subscribes to the server's message, and is used to receive the return of the server, which we will see when we write the client code.
So far, the service-side code coding finished! Next article we will write the client function.Wen/devid (author of Jane
Accidentally in the know to see a reply, instantly feel like so many of the information before the reply so that I have a websocket deep understanding of the wood has. So go to my blog and share. Prefer to read this kind of blog, reading it is easy, not boring, no preacher of the battle, purely for sharing. So much nonsense, and finally praise a ~One, WebSocket and HTTPWebSocket is the HTML5 (protocol), tha
Websocket protocol details and simple instance code, websocket details examples
Websocket protocol details
For more information about the websocket protocol, see other articles.
WebSocket keywords
HTML5 protocol, real-time, full-duplex communication, persistent
1. What is WebSocket?
WebSocket is a protocol specification proposed by HTML5, referring to rfc6455.
WebSocket the specification of a communication, through a handshake mechanism, between the client (browser) and the server (webserver) can establish a TCP-like connection, so as to facilitate communication between the
Directory
What is WebsocketWhy use WebsocketPerformance theory AnalysisWebsocket service end and reverse generation practiceTest for reverse generation performanceWebsocket and HTTPWhat is Websocket
The Websocket is a Full-duplex communication protocol, initially defined by HTML5, that is built on a single TCP connection, which is independent of the HTML5 speci
introduction to these open Source library files.
1. Pywebsocket
Pywebsocket is written in Python language, it can be a good cross-platform, the expansion is relatively simple, currently webkit use it to build WebSocket server to do layouttest.
We can get the source code through the following command
SVN checkouthttp://pywebsocket.googlecode.com/svn/trunk/pywebsocket-read-only
More detailed information can be obtained from the http://code.google.com/p
shutdown WebSocketThis is a critical step in making the whole process complete, and when a websocket communication is no longer in use, we have to manually turn off the WebSocket connection to the server. Close triggers the OnClose message, and then onclose inside, we release the memory.
_wsisendtext->close ();
using in LuaThe detailed code can ref
browser is similar to the following:
GET, HTTP, 1.1Connection: UpgradeUpgrade: websocketHost: example.comOrigin: nullSec-WebSocket-Key: sN9cRrP/n9NdMgdcy2VJFQ =Sec-WebSocket-Version: 13The above header information shows that an HTTP header is Upgrade. According to HTTP1.1, the Upgrade header indicates that the communication protocol is switched from HTTP/1.1 to the specified protocol. "
, developed from version 1.0 to 1.1, is a perfunctory improvement in cache handling, bandwidth optimization, and security, in addition to the default long connection. It retains a stateless, request/response pattern and never seems to realize that this should change.Fortunately, the era of HTML5 has arrived, for the implementation of Web-side instant Messaging brings WebSocket and SSE (Server-sent Events) t
handshake mechanism, between the client (browser) and the server (webserver) can establish a TCP-like connection, so as to facilitate communication between the c-s. Before the advent of WebSocket, web interaction was generally a short or long connection based on the HTTP protocol.
WebSocket is the technology that is g
in the corporate network.Now the HTML5 specification prepares an alternative for us. But this specification is a little bit ahead, many browsers are not supported, especially IE, for many developers today is not very helpful, given that most browsers have not yet implemented HTML5 WebSocket, the best way is still to use comet.WebSocket
WebSocket (Http://dev.w3.org/html5/websockets) is part of the HTML5 s
( "Disconnected");} //send Message to '/app/change-notice ' server function sendname (var value = document.getelementbyid ( ' name '). Value Stompclient.send ( "/app/change-notice", {}, value);} connect (); SCRIPT>
Related instructions:The functionality of JavaScript to implement WebSocket is simple, basically in the following steps:Open socket
var socket = new SockJS(‘/socket‘);Build a Sockjs object first
stompClient
to request a protocol upgrade (or in this case a protocol switch) to which the server can respond WI Th HTTP status (switching protocols) if it agrees. Assuming the handshake succeeds the TCP socket underlying the HTTP upgrade request remains open and both client and server can use it to send messages to each other.
The Spring Framework 4 includes a new Spring-websocket module with comprehensive websocket
Installation under CentOS6.5 environmentCheck if the Epel is installedYum RepolistIf you do not see the Epel in the results, install it via the Yum commandYum Install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmStart installing node. js After installing the above environmentsudo yum install Nodejs npm--enablerepo=epel2 Installing Websocket-benchUsing NPM to install in a global mannerNPM install-g
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.