Comprehensive Analysis of webkit HTML5 WebSocket 2

Source: Internet
Author: User

The previous article introduced websocket theory. This article analyzes the implementation of the websocket protocol client on the webkit browser engine.

For more information about websocket APIs, see RFC 6455.

The websocket implementation code on webkit is under the WebCore/websockets directory.


 
The following is the definition of webkit WebSocket JavaScript idl Interface (websocket. idl ):
 
 
The URL attribute indicates the network address of the WebSocket server. The protocol is generally "ws". The send method is to send data to the server, and the close method is to close the connection. In addition to these methods, there are also important events: onopen, onmessage, onerror, and onclose.
 
 
 
The js interface provided by the browser is used by web developers.
 
 
 
 
 
The above javascript code initiates a request for the client. The first is
Create a WebSocket object and specify the server url. the tcp request is initiated to the server when it is created. Therefore, the creation process is a blocking action, and webkit is implemented in V8WebsocketCustom. in cpp, the constructorCallback function is the constructor entry. After the url and protocol are parsed, The websocket-class connect function is called to initiate a tcp request.
WebSocket-> connect (url, toWebCoreString (protocol), ec );
Void WebSocket: connect (const String & url, const Vector <String> & protocols, ExceptionCode & ec) (websocket. cpp)
The function first performs some syntax checks, such as whether the protocol is ws or wss (secure ws), and then establishes a WebSocketChannel. We recommend that a websocoket channel represent the connected instance (WebSocketChannel. cpp ),
Last call ~ The connect function provided by WebSocketChannel first creates a handshake object WebSocketHandshake to save the handshake information. didCreateWebSocket-> didCreateWebSocketImpl initiates a tcp request.
The client initiates a connection request when constructing a websocket object, and then specifies the server Event Callback. For example, the onopen event indicates that the connection is established, and the onmessage indicates that the server has sent a message.





For more information about websocket, visit here.

 

Csdn lidp http://blog.csdn.net/perfectpdl

Related Article

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.