[go: up one dir, main page]

CN104394212A - A method for real-time website push message - Google Patents

A method for real-time website push message Download PDF

Info

Publication number
CN104394212A
CN104394212A CN201410683166.8A CN201410683166A CN104394212A CN 104394212 A CN104394212 A CN 104394212A CN 201410683166 A CN201410683166 A CN 201410683166A CN 104394212 A CN104394212 A CN 104394212A
Authority
CN
China
Prior art keywords
client
server
service
request
service end
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201410683166.8A
Other languages
Chinese (zh)
Inventor
庞毅
关班记
季统凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
G Cloud Technology Co Ltd
Original Assignee
G Cloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by G Cloud Technology Co Ltd filed Critical G Cloud Technology Co Ltd
Priority to CN201410683166.8A priority Critical patent/CN104394212A/en
Publication of CN104394212A publication Critical patent/CN104394212A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention relates to the technical field of software development, in particular to a method for pushing messages by a real-time website. The invention sends a request to a server through a web client, and the server blocks the request and returns the request until data transmission or overtime occurs; after the JavaScript response processing function of the client side processes the information returned by the server, the request is sent again, and the connection is reestablished; when the client processes the received data and reestablishes the connection, the server may have new data arriving; the information is stored by the server side until the web client side reestablishes the connection; the client retrieves all information of the current server once; therefore, the website user can receive the message sent by the server in real time, and the message receiving delay is avoided. The invention relates to real-time communication between a server and a client.

Description

一种实时网站推送消息的方法A method for real-time website push message

技术领域technical field

本发明涉及软件开发技术领域,具体涉及一种实时网站推送消息的方法。The invention relates to the technical field of software development, in particular to a method for pushing messages on a real-time website.

背景技术Background technique

现在是信息化时代,信息化使人类以更快更便捷的方式获得并传递人类创造的一切文明成果。信息的滞后,会带来一些不必要的麻烦,甚至是重大的经济损失。信息的及时性就显得尤为重要,在第一时间对获取的信息作出响应。.Now is the era of information technology, which enables human beings to obtain and deliver all the achievements of civilization created by human beings in a faster and more convenient way. The lag of information will bring some unnecessary troubles and even major economic losses. The timeliness of information is particularly important, and respond to the information obtained in the first time. .

发明内容Contents of the invention

本发明解决的技术问题在于提供一种实时网站推送消息的方法,为用户提供一种及时、高效的获取信息的方法。The technical problem to be solved by the present invention is to provide a method for pushing messages on a real-time website, so as to provide users with a timely and efficient method for obtaining information.

本发明解决上述技术问题的技术方案是:The technical scheme that the present invention solves the problems of the technologies described above is:

通过web客户端发送请求到服务端,服务器端阻塞请求直到有数据传递或超时才返回;之后客户端JavaScript响应处理函数在处理完服务器返回的信息后,再次发出请求,重新建立连接;当客户端处理接收的数据、重新建立连接时,服务器端可能有新的数据到达;这些信息会被服务器端保存直到web客户端重新建立连接;客户端一次将当前服务器端所有的信息取回;从而网站用户可以实时接收到服务端发送的消息,避免消息接收滞后。The request is sent to the server through the web client, and the server blocks the request until there is data transmission or timeout before returning; after the client JavaScript response processing function finishes processing the information returned by the server, it sends the request again and re-establishes the connection; when the client When processing the received data and re-establishing the connection, new data may arrive on the server side; this information will be saved by the server until the web client re-establishes the connection; the client will retrieve all the current server-side information at one time; thus website users The message sent by the server can be received in real time to avoid lagging in message reception.

所述的方法包括如下步骤:Described method comprises the steps:

第1步、首先客户端和服务端交互采用的Bayeux协议;Step 1. First, the Bayeux protocol used by the client and server for interaction;

第2步、客户端向服务端(/meta/handshake频道上)发起握手请求;Step 2, the client initiates a handshake request to the server (on the /meta/handshake channel);

第3步、服务端收到握手请求,BayeuxServer创造了一个半服务器对象的实例;服务端处理完握手请求后,发送响应给客户端;Step 3: The server receives the handshake request, and BayeuxServer creates an instance of a half-server object; after the server finishes processing the handshake request, it sends a response to the client;

第4步、客户端收到服务端处理握手请求的响应,如果成功,则:Step 4. The client receives the response from the server to process the handshake request. If successful, then:

a.向服务端发起订阅服务的请求;a. Initiate a subscription service request to the server;

b.开始与服务端的心跳机制,来交换连接的信息;b. Start the heartbeat mechanism with the server to exchange connection information;

第5步、服务端再启动时初始化两个服务频道Step 5: Initialize two service channels when the server restarts

a./service/privatechat自定义频道a./service/privatechat custom channel

b./service/joinlisten自定义频道b./service/joinlisten custom channel

第6步、客户端向服务端发起订阅/service/privatechat服务,此服务用来实现用户之间的聊天;Step 6: The client initiates a subscription/service/privatechat service to the server, which is used to implement chat between users;

第7步、开始心跳机制;Step 7, start the heartbeat mechanism;

第8步、心跳机制,建立HTTP长轮询;Step 8, heartbeat mechanism, establish HTTP long polling;

第9步、心跳机制,允许客户端检测服务器是否关闭了,并允许服务端检测客户端是否关闭了;Step 9, the heartbeat mechanism allows the client to detect whether the server is closed, and allows the server to detect whether the client is closed;

第10步、客户端和服务器之间的连接的消息一直都有,直至任何一方决定中断并发送一个disconnect的消息;Step 10, the connection message between the client and the server is always there, until either party decides to interrupt and send a disconnect message;

第11步、客户端可以向服务端/service/joinlisten频道发送请求;Step 11, the client can send a request to the server/service/joinlisten channel;

第12步、所有初始化工作都已准备完毕,客户端之间就可以任意发送信息。Step 12, all initialization work has been prepared, and information can be sent between clients arbitrarily.

本发明的有益效果是:通过实时网站推送消息的方法,让用户能及时的获取有用的信息,监控web应用的访问情况,实现及时发现问题、及时处理问题,大大减少客户无法访问应用的时间,把损失降到最低。The beneficial effect of the present invention is: through the method of real-time website pushing messages, users can obtain useful information in time, monitor the access status of web applications, realize timely discovery of problems and timely processing of problems, and greatly reduce the time that customers cannot access applications. Minimize losses.

附图说明Description of drawings

下面结合附图对本发明进一步说明:The present invention is further described below in conjunction with accompanying drawing:

图1为本发明的业务流程图。Fig. 1 is a business flow chart of the present invention.

具体实施方式Detailed ways

见附图所示,本发明通过web客户端发送请求到服务端,服务器端会阻塞请求直到有数据传递或超时才返回,之后客户端JavaScript响应处理函数会在处理完服务器返回的信息后,再次发出请求,重新建立连接。当客户端处理接收的数据、重新建立连接时,服务器端可能有新的数据到达;这些信息会被服务器端保存直到web客户端重新建立连接,客户端会一次把当前服务器端所有的信息取回,让网站用户可以实时接收到服务端发送的消息,避免消息接收滞后,造成的损失!As shown in the attached figure, the present invention sends a request to the server through the web client, and the server will block the request until there is data transmission or timeout before returning, and then the client JavaScript response processing function will process the information returned by the server, and then return to the server again. A request is made to re-establish the connection. When the client processes the received data and re-establishes the connection, new data may arrive on the server; this information will be saved by the server until the web client re-establishes the connection, and the client will retrieve all the current server-side information at one time , so that website users can receive the messages sent by the server in real time, avoiding delays in receiving messages and causing losses!

下面我们以某个推送消息的应用为例,讲述该方法的实施:Let's take an application that pushes messages as an example to describe the implementation of this method:

第1步、首先客户端和服务端交互采用的Bayeux协议;Step 1. First, the Bayeux protocol used by the client and server for interaction;

第2步、客户端向服务端(/meta/handshake频道上)发起握手请求。Bayeux协议要求,一个新的客户端发送的第一条消息是一个握手信息;Step 2: The client initiates a handshake request to the server (on the /meta/handshake channel). The Bayeux protocol requires that the first message sent by a new client is a handshake message;

第3步、服务端收到握手请求,BayeuxServer创造了一个半服务器对象的实例(一个ServerSession)。服务端处理完握手请求后,发送响应给客户端;Step 3, the server receives the handshake request, and BayeuxServer creates an instance of a half-server object (a ServerSession). After the server finishes processing the handshake request, it sends a response to the client;

第4步、客户端收到服务端处理握手请求的响应,如果它是成功,接下来要做两件事情:Step 4. The client receives the response from the server to process the handshake request. If it is successful, the next thing to do is two things:

a.向服务端发起订阅服务的请求。a. Initiate a request to the server to subscribe to the service.

b.开始与服务端的心跳机制,来交换连接的信息;b. Start the heartbeat mechanism with the server to exchange connection information;

第5步、服务端再启动时初始化了两个服务频道Step 5. Two service channels are initialized when the server restarts

a./service/privatechat自定义频道a./service/privatechat custom channel

b./service/joinlisten自定义频道b./service/joinlisten custom channel

第6步、客户端向服务端发起订阅/service/privatechat服务,此服务用来实现用户之间的聊天Step 6: The client initiates a subscription/service/privatechat service to the server, which is used to implement chat between users

第7步、开始心跳机制Step 7, start the heartbeat mechanism

第8步、心跳机制,建立HTTP长轮询。Step 8, heartbeat mechanism, establish HTTP long polling.

第9步、心跳机制,允许客户端检测服务器是否关闭了,并允许服务端检测客户端是否关闭了。Step 9, the heartbeat mechanism allows the client to detect whether the server is closed, and allows the server to detect whether the client is closed.

第10步、客户端和服务器之间的连接的消息一直都有,直至任何一方决定中断并发送一个disconnect的消息(发送/meta/disconnect断开通道消息)Step 10, the connection message between the client and the server has always been there, until either party decides to interrupt and send a disconnect message (send /meta/disconnect disconnect channel message)

第11步、客户端可以向服务端/service/joinlisten频道发送请求Step 11, the client can send a request to the server /service/joinlisten channel

第12步、所有初始化工作都已准备完毕,客户端之间就可以任意发送信息。Step 12, all initialization work has been prepared, and information can be sent between clients arbitrarily.

Claims (2)

1. a method for real-time website PUSH message, is characterized in that: transmit a request to service end by web client, and server end blocking request is until have data transmission or time-out just to return; The process of client JavaScript response afterwards function, after processing the information that server returns, again sends request, re-establishes connection; When the data that client process receives, re-establish connection time, server end may have new data to arrive; These information can be preserved until web client re-establishes connection by serviced device end; Client is once by information retrieval all for current server end; Thus website user can the message that sends to service end of real-time reception, avoids message sink delayed.
2. the method for real-time website PUSH message according to claim 1, is characterized in that: described method comprises the steps:
The Bayeux agreement that 1st step, first client and service end adopt alternately;
2nd step, client initiate handshake request to service end (on/meta/handshake channel);
3rd step, service end receive handshake request, and BayeuxServer creates the example of one and half server objects; After service end processes handshake request, send response to client;
4th step, client receive the response of service end process handshake request, if success, then:
A. the request of subscription service is initiated to service end;
B. start the heartbeat mechanism with service end, exchange the information of connection;
Initialization two service channels when 5th step, service end are restarted
The self-defined channel of a./service/privatechat
The self-defined channel of b./service/joinlisten
6th step, client are initiated to service end subscriptions/service/privatechat and are served, and this service is used for the chat realized between user;
7th step, beginning heartbeat mechanism;
8th step, heartbeat mechanism, set up the long poll of HTTP;
Whether whether the 9th step, heartbeat mechanism, allow client to detect server and close, and allow service end detection client to close;
The message of the connection between the 10th step, client and server has always, until either party determines to interrupt and sends the message of a disconnect;
11st step, client can send request to service end/service/joinlisten channel;
12nd step, all initial work are all ready, just can send information arbitrarily between client.
CN201410683166.8A 2014-11-23 2014-11-23 A method for real-time website push message Pending CN104394212A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410683166.8A CN104394212A (en) 2014-11-23 2014-11-23 A method for real-time website push message

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410683166.8A CN104394212A (en) 2014-11-23 2014-11-23 A method for real-time website push message

Publications (1)

Publication Number Publication Date
CN104394212A true CN104394212A (en) 2015-03-04

Family

ID=52612047

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410683166.8A Pending CN104394212A (en) 2014-11-23 2014-11-23 A method for real-time website push message

Country Status (1)

Country Link
CN (1) CN104394212A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106850745A (en) * 2016-12-23 2017-06-13 北京五八信息技术有限公司 A kind of real-time synchronization method and device
CN115103005A (en) * 2022-06-14 2022-09-23 北京京东乾石科技有限公司 Request response method and device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2000041359A1 (en) * 1998-12-31 2000-07-13 U S West, Inc. Narrowcast of individual information over a data network
CN102640449A (en) * 2009-11-06 2012-08-15 瑞典爱立信有限公司 System and methods for web-application communication
CN103095819A (en) * 2013-01-04 2013-05-08 微梦创科网络科技(中国)有限公司 Data information pushing method and data information pushing system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2000041359A1 (en) * 1998-12-31 2000-07-13 U S West, Inc. Narrowcast of individual information over a data network
CN102640449A (en) * 2009-11-06 2012-08-15 瑞典爱立信有限公司 System and methods for web-application communication
CN103095819A (en) * 2013-01-04 2013-05-08 微梦创科网络科技(中国)有限公司 Data information pushing method and data information pushing system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
吴亚峰 等: "用Ajax+Comet轻松实现实时Web聊天系统", 《网络与通信》 *
孙清国 等: "Web应用中的服务器推送技术研究综述", 《计算机系统应用》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106850745A (en) * 2016-12-23 2017-06-13 北京五八信息技术有限公司 A kind of real-time synchronization method and device
CN106850745B (en) * 2016-12-23 2021-01-15 北京五八信息技术有限公司 Real-time synchronization method and device
CN115103005A (en) * 2022-06-14 2022-09-23 北京京东乾石科技有限公司 Request response method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
EP2638680B1 (en) Full-duplex bi-directional communication over a remote procedure call based communications protocol, and applications thereof
US10027781B2 (en) TCP link configuration method, apparatus, and device
CN103535004B (en) Method and web-based system for facilitating anonymous audio and video communications
EP2688307A1 (en) Wireless communication system for offline participation in a display session
KR102208935B1 (en) Messaging api over http protocol to establish context for data exchange
HK1208970A1 (en) Processing method, device and system for message service and message service system
CN105610888A (en) Method of using socket to push message based on Android and system thereof
EP2991318B1 (en) Hybrid cloud architecture for media communications
WO2015180570A1 (en) Data channel establishment method and communications device
CN107258098A (en) Method and apparatus for the shared abundant information associated with calling
CN106941536A (en) Data interactive method between client and server based on http protocol
CN108683653A (en) A kind of active message push system based on WebSocket
CN106936730A (en) A kind of file transmitting method, TCP agent and TCP Client
CN104320328A (en) Message synchronization method, terminal and server
CN104486327A (en) Method and client side of communication between pages and long connection servers
WO2023150609A3 (en) Intelligent edge enabler client operation
CN110113623B (en) An audio and video slice transmission platform based on SIP protocol
EP2966832A2 (en) Multimedia conversation transfer
US20170359187A1 (en) Scalable real-time videoconferencing over WebRTC
CN102065143B (en) Communication method and system based on HTTP (hyper Text Transfer Protocol), HTTP server and HTTP client
CN105743852B (en) Method and system for realizing Socket connection maintaining communication across network gate through http
CN104394212A (en) A method for real-time website push message
US9137104B2 (en) Method and apparatus of performing remote management of a managed machine
WO2014117506A1 (en) Method and device for sending multimedia message to group member
CN104995898A (en) Method, device and system for establishing data channel

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20150304

WD01 Invention patent application deemed withdrawn after publication