When you import large quantities of data, you need to immediately display the progress of processing the files. Consider that Ajax polling is too wasteful for resources to be implemented using WebSocket.The project uses spring MVC (3.1), which is combined with WebSocket to require version 4.0 or more. Therefore, the websocket provided by spring is not used.1. Dep
WebSocket and the traditional socket programming, although there are differences, but also there is a concept of the same, also sub-server and client.Main differences
For WebSocket, the client is written by JS write callback function to complete the interaction, while the traditional socket, you need to connect the port, through the input and output stream to pass information, complete the interact
the horizontal ordinate, SW, SH when the width of the copied area of the height //dx, DY is the starting horizontal ordinate of the copied target image in the canvas, DW,DH is the width of the copied target image.ctx.drawimage (img,offsetx,offsety,imgwidth,imgheight)//var base64 = canvas.todataurl (' img/png ', 0.7)//parameter indication: Specified picture type, picture quality //if (typeof objdiv = = = = ' object ') {objdiv.appendchild (Canvas)//Console.log (base64) //} el
principle and programming interface of WebSocket. The next step is to demonstrate how to implement a WebSocket application in a simple case, and to demonstrate how WebSocket is perfectly unified in both powerful and easy-to-use programming. Finally, this paper introduces the current situation, limitations and future prospects of mainstream browsers for
existing browser must clearly know the protocol type, in order to properly establish a long connection, and processing the WebSocket package, and the use of the relevant JS code, so the handshake becomes important.
When implementing our own server, the purpose of building a handshake is to properly notify the client that the server can receive and allow a connection based on the
channel between the two parties is established. The WebSocket handshake information processing logic is implemented, and a WebSocket server with basic functions is complete. The entire WebSocket server consists of two core classes: WebSocketServer and SocketConnection. For the sake of space, we will not introduce the
, superchatsec-websocket-version:13origin:http://example.comFamiliar with the HTTP children's shoes may have found, this is similar to the HTTP protocol handshake request, a few more things. I'll explain the effect by the way.Upgrade:websocketConnection:UpgradeThis is the core of WebSocket, tell Apache , and Nginx so on server: notice, I initiated is the WebSocket
implement a WebSocket application in a simple case, and to demonstrate how WebSocket is perfectly unified in both powerful and easy-to-use programming. Finally, this paper introduces the current situation, limitations and future prospects of mainstream browsers for WebSocket support.The dilemma of real-time WEB applicationsThe WEB application's information inter
Original address: http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/WebSocket Past LifeAs we all know, the interactive process of WEB application is usually the client sends a request through the browser, the server side receives the request to process and returns the result to the client, the client browser presents the information, this mechanism is not very frequent for the information change appl
programming interface of WebSocket. The next step is to demonstrate how to implement a WebSocket application in a simple case, and to demonstrate how WebSocket is perfectly unified in both powerful and easy-to-use programming. Finally, this paper introduces the current situation, limitations and future prospects of mainstream browsers for
interface of WebSocket. The next step is to demonstrate how to implement a WebSocket application in a simple case, and to demonstrate how WebSocket is perfectly unified in both powerful and easy-to-use programming. Finally, this paper introduces the current situation, limitations and future prospects of mainstream browsers for
" answer, otherwise the client throws an "error during WebSocket handshake" fault and closes the connection.The data format returned by the server after receiving the message is similar:Listing 2.WebSocket Service-side response messageshttp/1.1101 switching ProtocolsUpgrade:websocketConnection:UpgradeSec- websocket-accept:k7djldlooiwig/mopvwfb3y3fe8=The value of
information. That is to say, it is a solution, but it is not the best technical solution.Currently, browsers such as IE do not support WebSocket. What should we do if we want to provide WebSocket event processing, return transmission, and use a unified API on the server? Fortunately, Guillermo Rauch creates a Socket. IO technology.3.
connection.The data format returned by the server after receiving the message is similar:Listing 2.WebSocket Service-side response messageshttp/1.1 101 Switching protocolsupgrade:websocketconnection:upgradesec-websocket-accept:k7djldlooiwig/ mopvwfb3y3fe8=The value of "Sec-websocket-accept" is returned to the client after the server is computed with a client-con
// Connect to websocket
Var ws = new WebSocket ("ws: // FIG: 8000 ");
// When the websoc is successfully connected
Ws. onopen = function (){}
// The message output by the server is obtained successfully.
Ws. onmessage = function (e ){}
// When a connection error occursWs. onerror = function (){}
//Send data to the server
Ws. send ();
3. Background
The difficulties of w
as follows:
Ws = new WebSocket (address );Ws. onopen = function (e ){Var msg = document. createElement ('P ');Msg. style. color = '#0f0 ';Msg. innerHTML = "Server> connection open .";MsgContainer. appendChild (msg );Ws. send ('{
You can also bind events.
The Code is as follows:
Ws = new WebSocket (address );Ws. addEventListener ('open', function (e ){Var msg = document. createElement ('P ');Msg. styl
-origin:http://localhost:8080Upgrade:websocket(Challenge Response): ac:23:a5:7e:5d:e5:04:6a:b5:f8:cc:e7:ab:6d:1a:39The WebSocket handshake uses all of these headers to validate and set a long-lived connection, and the WebSocket JavaScript object also contains two useful properties:Ws.url: Returns the URL of the WebSocket serverWs.readystate: Returns the value of
-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==Sec-WebSocket-Protocol: chat, superchatSec-WebSocket-Version: 13
First, Sec-websocket-key is the value of a Base64 encode, which is randomly generated by the browser, telling the server to verify the WebSocket protocol.Then, Sec_websoc
acceptable.Even in scenarios where low latency is required, if the number of messages transmitted is low (for example, a scenario that monitors network failures), you should consider using long polling techniques.And only in low-latency and high-frequency message communication scenarios, the choice of WebSocket protocol is very suitable. Even with this scenario, there is still a choice of websocket communi
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.