WO2013097401A1 - Method, gateway and communication system for browser client directly communicating with back-end server - Google Patents

Method, gateway and communication system for browser client directly communicating with back-end server Download PDF

Info

Publication number
WO2013097401A1
WO2013097401A1 PCT/CN2012/075776 CN2012075776W WO2013097401A1 WO 2013097401 A1 WO2013097401 A1 WO 2013097401A1 CN 2012075776 W CN2012075776 W CN 2012075776W WO 2013097401 A1 WO2013097401 A1 WO 2013097401A1
Authority
WO
WIPO (PCT)
Prior art keywords
address
port
backend server
browser client
gateway
Prior art date
Application number
PCT/CN2012/075776
Other languages
French (fr)
Chinese (zh)
Inventor
关国锋
朱建峰
范家星
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2013097401A1 publication Critical patent/WO2013097401A1/en

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/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]

Definitions

  • the present invention relates to the field of communications, and in particular, to a method, a gateway, and a communication system for a browser client to communicate with a backend server.
  • BACKGROUND Real-time Web is a kind of Internet application in the Web2.0 system, and its typical representative mainly includes the social networking websites Facebook and Twitter.
  • real-time web applications such as social networking sites Facebook and twitter microblogging
  • the web server needs to actively push the user's friend's output (feed) information to the user in real time, so that users and their friends can generate and share anytime, anywhere. And consumer content.
  • Other web applications such as monitoring, instant messaging, and real-time quoting systems also require the server to deliver changes in the background to the client in real time.
  • HTTP-based polling which illustrates a method for real-time interaction between a browser provided by a prior art and a back-end server to obtain real-time update information, including the following steps: S11, the browser connects to the web application server through the web, and is based on HTTP to the web.
  • the application server sends an HTTP request; 512.
  • the web application server receives and parses the browser's HTTP request, and converts the HTTP request into a call to the extended custom application service program;
  • the extended custom application service program parses the web application logic and protocol, and converts the web application logic and protocol into a standard API or message call to the backend server; and S14, the extended custom application service program invokes the corresponding message client program. , for example, RSS
  • JMS Java Message Service
  • EJB Enterprise Java Bean
  • XMPP The Extensible Messaging and Presence Protocol
  • Comet technology sends the information to the browser for display.
  • the session between the browser and the web application server and the session between the web application server and the back-end server are completely independent and separated. Therefore, the above prior art has the following drawbacks: 1) The resource waste is serious. Since the information carried by the HTTP protocol is often only a few bytes, and the HTTP header is too large (nearly 1K), that is, there are many invalid information payloads. Therefore, frequent polling causes system bandwidth consumption and high latency;
  • the system has a performance bottle head. Since the web server between the browser and the back-end server needs to run the main business logic and calculation, the performance of the web server becomes the performance bottleneck of the system; 3) the end-to-end full-duplex communication cannot be realized.
  • the communication between the browser and the web application server is Based on the HTTP protocol, such as the traditional HTTP polling or Comet technology, to obtain real-time information; since the traditional HTTP polling is half-duplex, the Comet technology based on the HTTP protocol needs to implement two-way communication on two connections, so it is more expensive to use the server. Resources, end-to-end full-duplex communication cannot be achieved between the browser and the back-end server. Summary of the invention
  • Embodiments of the present invention provide a method, a gateway, and a communication system for a browser client to communicate with a backend server to achieve end-to-end full-duplex communication between a browser client and a backend server while improving resource utilization.
  • An embodiment of the present invention provides a method for a browser client to communicate with a backend server.
  • the method includes: receiving, by a gateway, a TCP control connection of a browser client, a user request message sent by a browser client, where the user
  • the request message includes: an IP address and a port of the browser client;
  • An embodiment of the present invention provides a gateway, where the gateway includes:
  • a receiving module configured to receive, by using a gateway, a transmission control protocol (TCP) connection of the browser client, a user request message sent by the browser client, where the user request message includes: an IP address and a port of the browser client;
  • a first obtaining module configured to obtain, according to an IP address and a port query message forwarding table of the browser client, an IP address and a port of a backend server associated with an IP address and a port of the browser client;
  • a sending module configured to send, by using a TCP connection between the gateway and the backend server, the user request message to the IP address and port corresponding to the backend server according to an IP address and a port of the backend server End server.
  • An embodiment of the present invention provides a communication system, where the communication system includes: a browser client, a gateway, and a backend server; and the browser client is configured to send a user request by using a TCP connection with the gateway of the gateway.
  • the user request message includes: an IP address and a port of the browser client; the gateway, configured to receive, by using the TCP connection with a browser client, the user request message sent by a browser client;
  • the user request message in the browser client's IP address and port query message forwarding table obtain the IP address and port of the backend server associated with the browser client's IP address and port; according to the IP of the backend server An address and a port, the user request message is sent to a backend server corresponding to an IP address and a port of the backend server by a TCP connection with the backend server; the backend server is configured to receive User request message forwarded by the gateway.
  • the gateway since the gateway establishes a TCP long connection with the browser client and the backend server, on the one hand, the browser client can implement full duplex communication with the backend server, and the real time information of the browser client Nearly the release time can be sent to the back-end server in real time, so the real-time performance is strong; on the other hand, the gateway is responsible for forwarding the browser client to the back-end server through the TCP connection.
  • the user request message, the main business logic and calculation are distributed in the browser client and the back-end server. The gateway does not need to undertake the main business logic and calculation, and does not need to use additional resources to realize the protocol conversion between the HTTP and the back-end server. This saves overhead.
  • FIG. 1 is a schematic flowchart of a method for directly connecting a browser client and a backend server according to an embodiment of the present invention
  • FIG. 2 is a schematic diagram of interaction between a browser client, a WebSocket gateway, and a backend server in a method in which a browser client and a backend server are directly connected according to an embodiment of the present invention
  • FIG. 3 is a schematic structural diagram of a gateway according to an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of a gateway according to another embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of a gateway according to another embodiment of the present invention.
  • FIG. 6 is a schematic structural diagram of a gateway according to another embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of a communication system according to an embodiment of the present invention.
  • FIG. 8 is a schematic diagram of a physical connection of a communication system according to an embodiment of the present invention.
  • FIG. 1 is a schematic flowchart of a method for directly connecting a browser client and a backend server according to an embodiment of the present invention.
  • the method illustrated in FIG. 1 is a communication protocol in which a browser is a web browser, a gateway is a Web socket gateway, a web socket gateway communicates with a browser client, and a back server is an HTML5 standard WebSocket protocol, and its execution is performed.
  • the subject can be
  • WebSocket gateway mainly includes steps:
  • S101 Receive a user request message sent by the browser client by using a TCP control connection between the gateway and the browser client, where the user request message includes: an IP address and a port of the browser client.
  • the method may further include: receiving, by using a TCP connection between the gateway and the browser client, a handshake request message sent by the browser client, where the handshake request message includes an IP address and a port of the backend server;
  • the request message establishes a TCP connection between the gateway and the backend server; associates an IP address and a port of the browser client with an IP address and a port of the backend server, and updates the association relationship to the message Published.
  • the establishing a TCP connection between the gateway and the backend server according to the handshake request message may be: extracting an IP address and a port of the backend server included in the handshake request message; according to the backend server The IP address and port establish a TCP connection between the gateway and the backend server.
  • the browser client when the user accesses the gateway, the browser client sends an application download request to the gateway, and downloads the web application from the gateway to the browser client. Thereafter, in order to obtain real-time information from the backend server, the user runs the web application on the browser client to request to establish a Transmission Control Protocol (TCP) connection with the gateway.
  • TCP Transmission Control Protocol
  • the browser client can send the gateway to the gateway through the TCP connection, and the gateway receives the user request message through the TCP, for example, a subscription request, where the user request message includes the IP of the browser client.
  • Information such as address and port indicates the source.
  • the browser client may send a handshake request message to the gateway, and the handshake request message is based on the HTTP protocol.
  • the gateway receives the handshake request message sent by the browser client through its TCP connection with the browser client.
  • the gateway sends a response message to the browser client, the negotiation between the browser client and the gateway is successful.
  • the interaction between the browser client and the gateway is based on the WebSocket protocol.
  • the WebSocket protocol message can pass.
  • the TCP connection is transmitted.
  • the header of the WebSocket protocol message is very small, that is, the overhead of the message is small, it is more efficient than the transmission of the HTTP protocol by the browser and the web application server in the prior art; on the other hand, due to the gateway and The communication protocol for the browser client and the backend server to communicate is the HTML5 standard WebSocket protocol instead of the private custom protocol, so the versatility is good.
  • the handshake request message received by the gateway may include information such as an IP address of the backend server, a port, and a communication protocol of the backend server, where the communication protocol of the backend server is an option in the handshake request message, that is, the handshake request message may be The communication protocol of the backend server is not included, and the communication protocol of the backend server can be preconfigured.
  • the IP address of the backend server, the port, and the communication protocol of the backend server can be obtained by adding a cell to the handshake request message, as shown below, which is an HTTP Upgrade handshake of the newly added cell in the handshake request message.
  • Example of a request message is an HTTP Upgrade handshake of the newly added cell in the handshake request message.
  • the new cell "DestHost: tcp: ⁇ myDestHostAddress: 9960,,” is used to declare the IP address of the backend server, the port, and the communication protocol of the backend server.
  • the backend server The communication protocol is TCP.
  • the gateway After receiving the handshake request message sent by the browser client, the gateway establishes its TCP connection with the backend server according to the handshake request message. Specifically, the gateway extracts an IP address and a port of the backend server included in the handshake request message, and then establishes a TCP connection of the gateway to the backend server according to the IP address and port of the backend server.
  • S102 Query a message forwarding table according to the IP address and port of the browser client, and obtain an IP address and a port of the backend server associated with the IP address and port of the browser client.
  • the gateway maintains a message forwarding table, and when a new connection is established, the gateway may update the message forwarding table. For example, after receiving the handshake request message and establishing a TCP connection of the gateway to the backend server, the gateway may update the message forwarding table, that is, record the IP address, port, and the backend server of the backend server. Communication protocol and information such as the IP address and port of the browser client.
  • the gateway after the gateway establishes a TCP connection between the gateway and the backend server according to the handshake request message sent by the browser client, the gateway sets the IP address of the browser client, the IP address of the port and the server of the backend server, and the port.
  • the updated message forwarding table includes an IP address of the backend server, a port, a communication protocol of the backend server, and an IP address of the browser client.
  • Information such as a port, and can record an IP address of the browser client, an IP address of the port and the backend server, and a port association relationship.
  • the meaning of the message forwarding table recording these associations is that, according to the IP address and port of the browser client, by querying the message forwarding table, the IP address, port, or vice versa of the backend server associated with it can be obtained, according to the backend server.
  • the IP address and port can be obtained by querying the message forwarding table to obtain the IP address and port of the browser client associated with it.
  • the gateway can also establish the connection with the backend server after listening to the "establishment connection request" message of these broadcasts.
  • the present invention does not limit the manner in which the gateway establishes a TCP connection with the backend server.
  • S103 Send a user request message to the backend server corresponding to the IP address and port of the backend server by using a TCP connection between the gateway and the backend server according to the IP address and port of the backend server.
  • the gateway When the user sends a request message through the browser client, the gateway receives the request message sent by the browser client. Due to the network protocol layer (for example, the IP layer) below the application layer, the gateway can parse out the IP address of the back-end server included in the request message, the port, and the communication protocol of the back-end server. Therefore, the gateway can query the update.
  • Message forwarding table ie, the gateway is based on the browser client
  • the IP address, port query message forwarding table obtains the IP address and port of the backend server associated with the browser client's IP address and port. And sending, according to the obtained backend server IP address and port, the request message to a backend server corresponding to the IP address and port of the backend server, thereby implementing the gateway and the A TCP connection of the backend server, forwarding a message of interaction between the browser client and the backend server.
  • the method provided by the embodiment of the present invention may further include: using a gateway and a backend server
  • the TCP connection receives the request response message sent by the backend server, where the request response message includes: an IP address and a port of the backend server; and querying the message forwarding table according to the IP address and port of the backend server, Obtaining an IP address and port of a browser client associated with the IP address and port of the backend server; and according to the IP address and port of the browser client, the request is made through a TCP connection between the gateway and the browser client The response message is sent to a browser client corresponding to the IP address and port of the browser client.
  • the backend server When the backend server receives the request message forwarded through the gateway, it sends a request response message to the gateway.
  • the gateway receives a request response message sent by the backend server through a TCP connection with the backend server, where the request response message is a response to a user request message sent by the browser client, where the IP address and port of the backend server are included. It can also contain information such as the communication protocol of the backend server.
  • the gateway can parse out the IP address of the backend server included in the request response message, the communication protocol of the port and the backend server, etc., so the gateway can query the location.
  • the updated message forwarding table that is, the gateway queries the updated message forwarding table according to the IP address and port of the backend server, and obtains the IP of the browser client associated with the IP address and port of the backend server. Address, port.
  • the request response message is forwarded to a browser client corresponding to the IP address and port of the browser client according to the acquired IP address and port of the browser client, thereby implementing the establishment established by the front gateway.
  • the TCP connection of the browser client forwards a message exchanged between the browser client and the backend server.
  • the method for the direct connection between the browser client and the backend server provided by the embodiment of the present invention can be seen that, since the gateway and the browser client and the backend server can establish a TCP long connection, on the one hand, the browser client can be followed by The end server implements full-duplex communication, and the real-time information of the browser client The release time can be sent to the backend server in real time, so the real-time performance is strong; on the other hand, the gateway passes
  • the TCP connection is responsible for forwarding the user request message sent by the browser client to the back-end server.
  • the main business logic and calculation are distributed among the browser client and the back-end server.
  • the gateway does not need to undertake the main business logic and calculation, and does not need to consume. Additional resources enable protocol conversion between HTTP and the backend server, thus saving overhead.
  • the interaction between the browser client, the WebSocket gateway, and the backend server mainly includes:
  • the browser client sends a web application download request to the WebSocket gateway.
  • the web application download request is that when the user accesses the gateway, the browser client sends the access request to the WebSocket gateway.
  • the WebSocket gateway downloads the web application to the browser client.
  • the browser client runs the web application.
  • the browser client receives a real-time information request message input by the user.
  • the browser client sends a handshake request message to the WebSocket gateway through the web application.
  • the browser client can send a handshake request message based on the HTTP format to the gateway to request to negotiate a communication protocol with the gateway.
  • the handshake request message includes an IP address and a port of the backend server, and optionally, a communication protocol of the backend server, and the like.
  • the IP address and port of the backend server may optionally include information such as a communication protocol of the backend server.
  • the new cell "DestHost: tcp: ⁇ myDestHostAddress: 9960,” is used to declare the IP address of the backend server, the port, and the communication protocol of the backend server.
  • the backend server The communication protocol is TCP.
  • the WebSocket gateway parses the handshake request message.
  • the gateway resolves the handshake request message, extracts the IP address and port of the backend server included therein, and then establishes a TCP connection between the gateway and the backend server according to the IP address and port of the backend server, including:
  • the WebSocket gateway sends a TCP connection establishment request to the backend server.
  • the backend server returns a response message to the WebSocket gateway.
  • WebSocket Gateway updates the message forwarding table.
  • the WebSocket gateway records the IP address of the backend server, the port, the communication protocol of the backend server, and the IP address and port of the browser client in the message forwarding table, and the updated message forwarding table includes The IP address, port, and the backend server of the backend server
  • the communication protocol and the information such as the IP address and port of the browser client, and the IP address of the browser client, the IP address of the port and the backend server, and the port association relationship may be recorded.
  • the gateway establishes a TCP connection between the gateway and the backend server according to the handshake request message sent by the browser client, and associates the IP address and port of the browser client with the IP address and port of the backend server, and Updating the association relationship to the message forwarding table. Therefore, the updated message forwarding table includes information such as an IP address of the backend server, a port, a communication protocol of the backend server, and an IP address and port of the browser client, and includes the browser client. The IP address and port are associated with the IP address and port of the backend server.
  • the meaning of the message forwarding table recording these associations is that, according to the IP address and port of the browser client, by querying the message forwarding table, the IP address, port, or vice versa of the backend server associated with it can be obtained, according to the backend server.
  • the IP address and port can be obtained by querying the message forwarding table to obtain the IP address and port of the browser client associated with it.
  • the WebSocket gateway sends a handshake request response message to the browser client.
  • the handshake request response message sent by the WebSocket gateway to the browser client indicates that the WebSocket gateway successfully establishes a TCP connection with the browser client and the backend server, and subsequent message interaction between the browser client and the backend server can be performed through the TCP connection. .
  • the browser client sends a message subscription request to the WebSocket gateway.
  • the message subscription request includes information such as an IP address of the backend server, a port, and a communication protocol of the backend server.
  • the WebSocket gateway parses the message subscription request.
  • the network protocol layer (for example, the IP layer) below the application layer, the WebSocket gateway can parse out
  • the message subscription request includes information about the IP address of the backend server, the port, and the communication protocol of the backend server. Therefore, the WebSocket gateway can query the updated message forwarding table in step S209, that is, the WebSocket gateway browses according to the message.
  • the IP address and port of the client query the message forwarding table, and obtain the IP address and port of the backend server associated with the browser client.
  • the WebSocket gateway sends a message subscription request to the backend server.
  • the WebSocket gateway sends the message subscription request to the backend server corresponding to the IP address and port of the backend server according to the obtained IP address and port of the backend server.
  • the backend server sends a request response message corresponding to the message subscription request to the WebSocket gateway.
  • the response message corresponding to the message subscription request includes the IP address and port of the backend server, and may also contain information such as the communication protocol of the backend server.
  • the WebSocket gateway forwards the response message of the backend server to the browser client.
  • the backend server sends an update message to the WebSocket gateway.
  • the update message is the message requested by the message subscription request.
  • the WebSocket gateway parses a response message corresponding to the message subscription request.
  • the WebSocket gateway can parse the IP address, port, and backend server of the backend server backend server included in the request response message corresponding to the message subscription request.
  • the information such as the communication protocol, the WebSocket gateway can query the updated message forwarding table in step S209, that is, the WebSocket gateway queries the updated message forwarding table according to the IP address and port of the backend server, and obtains the information forwarding table.
  • Server The IP address and port of the associated browser client.
  • the WebSocket gateway forwards the update message to the browser client.
  • the WebSocket gateway queries the corresponding browser communication connection through the IP address and port of the browser client according to the obtained IP address and port of the browser client associated with the backend server, and sends the backend server to the WebSocket in step S216.
  • the update message sent by the gateway is forwarded to the browser client corresponding to the IP address and port of the browser client.
  • the browser client sends a response message corresponding to the update message to the WebSocket gateway.
  • the response message is an acknowledgment of the update message forwarded by the WebSocket gateway.
  • the WebSocket gateway sends a response message corresponding to the update message to the backend server.
  • FIG. 3 it is a schematic diagram of a gateway structure provided by an embodiment of the present invention. For the convenience of description, only parts related to the embodiment of the present invention are shown.
  • the gateway illustrated in Figure 3 may be a WebSocket gateway, and the communication protocol for communicating with the browser client and the backend server may be the HTML5 standard WebSocket protocol.
  • the gateway illustrated in FIG. 3 includes a receiving module 301, a first obtaining module 302, and a transmitting module 303, where:
  • the receiving module 301 is configured to receive, by using a gateway and a transmission control protocol TCP connection of the browser client, a user request message sent by the browser client, where the user request message includes: an IP address and a port of the browser client;
  • the first obtaining module 302 is configured to query the message forwarding table according to the IP address and port of the browser client, and obtain an IP address and a port of the backend server associated with the IP address and port of the browser client.
  • a sending module 303 configured to use, according to the IP address and port of the backend server, by using a gateway
  • the TCP connection of the backend server sends the user request message to a backend server corresponding to the IP address and port of the backend server.
  • the receiving module 301 receives the request message sent by the browser client. Because the network protocol layer (for example, the IP layer) below the application layer can parse the IP address of the back-end server included in the request message, the port, and the communication protocol of the back-end server, the first obtaining module 302 can query The updated message forwarding table, that is, the first obtaining module 302 obtains the IP of the backend server associated with the IP address and port of the browser client according to the IP address of the browser client and the port query message forwarding table. Address and port.
  • the updated message forwarding table that is, the first obtaining module 302 obtains the IP of the backend server associated with the IP address and port of the browser client according to the IP address of the browser client and the port query message forwarding table. Address and port.
  • the sending module 303 sends the request message to the backend server corresponding to the IP address and port of the backend server according to the obtained backend server IP address and port, thereby implementing the gateway and the A TCP connection of the backend server, forwarding a message of interaction between the browser client and the backend server.
  • the gateway and the browser client and the backend server can establish a TCP long connection
  • the browser client can implement full duplex communication with the backend server, and the browser
  • the real-time information of the client can be sent to the back-end server in real time near the release time, so the real-time performance is strong
  • the gateway is responsible for forwarding the user request message sent by the browser client to the back-end server through the TCP connection, the main Business logic and calculations are distributed across browser clients and back-end servers.
  • the gateway does not need to undertake major business logic and calculations, and does not require additional resources to implement protocol conversion between HTTP and back-end servers, thus saving overhead.
  • each functional module is only an example. In actual applications, the foregoing functional allocation may be different according to requirements, such as configuration requirements of corresponding hardware or convenience of implementation of software.
  • the functional module is completed, that is, the internal structure of the gateway is divided. Different functional modules to complete all or part of the functions described above.
  • the corresponding functional modules in this embodiment may be implemented by corresponding hardware, or may be executed by corresponding hardware.
  • the foregoing receiving module may have the foregoing
  • the transmission control protocol TCP connection of the browser client receives the hardware of the user request message sent by the browser client, such as a receiver, or a general processor or other hardware device capable of executing the corresponding computer program to perform the foregoing functions
  • the first obtaining module may be configured to execute the foregoing to forward the table according to the IP address and port query message of the browser client, and obtain the IP address and port of the backend server associated with the IP address and port of the browser client.
  • the functional hardware such as the first acquirer, may also be a general processor or other hardware device capable of executing a corresponding computer program to perform the aforementioned functions (the various embodiments provided herein may apply the above described principles).
  • the gateway illustrated in FIG. 3 may further include a handshake message receiving module 401, a connection establishing module 402, and an update module 403. As shown in FIG. 4, a gateway provided by another embodiment of the present invention, wherein:
  • the handshake message receiving module 401 is configured to receive, by using a TCP connection between the gateway and the browser client, a handshake request message sent by the browser client, where the handshake request message includes an IP address and a port of the backend server;
  • the browser client may send a handshake request message to the gateway, and the handshake request message is based on the HTTP protocol.
  • the handshake message receiving module 401 receives the handshake request message sent by the browser client through the TCP connection between the gateway and the browser client.
  • the gateway sends a response message to the browser client, the negotiation between the browser client and the gateway is successful.
  • the interaction between the browser client and the gateway is based on the WebSocket protocol.
  • the message can be transmitted over the TCP connection.
  • the header of the WebSocket protocol message is very small, that is, the overhead of the message is small, it is more efficient than the transmission of the HTTP protocol by the browser and the web application server in the prior art; on the other hand, due to the gateway and The communication protocol for the browser client and the backend server to communicate is the HTML5 standard WebSocket protocol instead of the private custom protocol, so the versatility is good.
  • the handshake request message received by the handshake message receiving module 401 may include information such as an IP address of the backend server, a port, and a communication protocol of the backend server, where the communication protocol of the backend server is an option in the handshake request message, that is, The handshake request message may not include the communication protocol of the backend server, and the information of the communication protocol of the backend server may be pre-configured.
  • the IP address of the backend server, the port, and the communication protocol of the backend server can be obtained by adding a cell to the handshake request message, as shown below, which is an HTTP Upgrade handshake of the newly added cell in the handshake request message.
  • the new cell "DestHost: tcp: ⁇ myDestHostAddress: 9960,," is used to declare the IP address of the backend server, the port, and the communication protocol of the backend server.
  • the backend server The communication protocol is TCP.
  • a connection establishing module 402 configured to establish, according to the handshake request message, a TCP connection between the gateway and the backend server;
  • the update module 403 is configured to associate an IP address and a port of the browser client with an IP address and a port of the backend server, and update the association relationship into the message forwarding table.
  • the gateway illustrated in FIG. 3 may further include a response message receiving module 501, a second obtaining module 502, and a response message sending module 503.
  • the gateway provided by another embodiment of the present invention, where: the response message receiving module 501 Receiving a request response message sent by the backend server by using a TCP connection between the gateway and the backend server, where the request response message includes: an IP address and a port of the backend server;
  • the second obtaining module 502 is configured to query the message forwarding table according to the IP address and port of the backend server, and obtain an IP address and a port of a browser client associated with an IP address and a port of the backend server;
  • the response message sending module 503 is configured to send the request response message to the IP address and port of the browser client by using a TCP connection between the gateway and the browser client according to the IP address and port of the browser client.
  • the corresponding browser client is configured to send the request response message to the IP address and port of the browser client by using a TCP connection between the gateway and the browser client according to the IP address and port of the browser client.
  • the gateway illustrated in FIG. 4 may further include a response message receiving module 501, a second obtaining module 502, and a response message sending module 503 as shown in FIG. 5, and the functions are as described above, and details are not described herein again.
  • the gateway maintains a message forwarding table, and when a new connection is established, the update module 403 may update the message forwarding table.
  • the update module 403 may be updated, that is, the IP address of the backend server, the port, the communication protocol of the backend server, and the IP address and port of the browser client are recorded.
  • the update module 403 sets the IP address, port and backend server of the browser client.
  • the updated message forwarding table includes information such as an IP address of the backend server, a port, a communication protocol of the backend server, and an IP address and port of the browser client, and may record the browser client.
  • the IP address and port of the terminal are associated with the IP address and port of the backend server.
  • the meaning of the association relationship recorded by the message forwarding table is that the first ear module 302 can obtain the IP address and port of the backend server associated with it by querying the message forwarding table according to the IP address and port of the browser client. Or vice versa, the second obtaining module 502 can obtain the IP address and port of the browser client associated with the message forwarding table according to the IP address and port of the backend server.
  • connection establishing module 402 may further include a parsing unit 601 and an establishing unit 602, such as the gateway provided by another embodiment of the present invention, as shown in FIG.
  • the parsing unit 601 is configured to extract an IP address and a port of the backend server included in the handshake request message;
  • the establishing unit 602 is configured to establish a TCP connection between the gateway and the backend server according to the IP address and port of the backend server.
  • the communication system illustrated in FIG. 7 includes a browser client 701, a backend server 703, and a gateway 702 of any of FIGS. 3 through 6, wherein:
  • the browser client 701 is configured to send, by using a transmission control protocol TCP connection with the gateway, a user request message, where the user request message includes: an IP address and a port of the browser client;
  • the gateway 702 is configured to receive, by using the TCP connection with the browser client, the user request message sent by the browser client, according to the IP address and the port query message forwarding table of the browser client in the user request message, Obtaining an IP address and a port of the backend server associated with the IP address and port of the browser client; according to the IP address and port of the backend server, the user request is made through a TCP connection with the backend server Sending a message to a backend server corresponding to the IP address and port of the backend server;
  • the backend server 703 is configured to receive a user request message forwarded by the gateway.
  • the browser client 701 is further configured to send a handshake request message by using a TCP connection with the gateway 702, where the handshake request message includes an IP address and a port of the backend server;
  • the gateway 702 is further configured to receive, by using a TCP connection with the browser client 701, the handshake request message sent by the browser client 701; and establish a session with the backend server 703 according to the handshake request message. Describe the TCP connection; associate the IP address and port of the browser client 701 with the IP address and port of the backend server, and update the association relationship to the message forwarding table.
  • the backend server 703 is further configured to send a request response message to the gateway 702 through a TCP connection with the gateway 702, where the request response message includes: an IP of the backend server
  • the gateway 702 is further configured to receive, by using a TCP connection with the backend server, a request response message sent by the backend server 703; according to the IP address of the backend server 703 in the request response message
  • the port queries the message forwarding table, obtains the location The IP address of the backend server 703 and the IP address and port of the browser client 701 associated with the port; according to the IP address and port of the browser client 701, through the browser client 701
  • the TCP connection sends the request response message to a browser client corresponding to the IP address and port of the browser client 701; the browser client 701 is further configured to: receive the Request response message.
  • FIG. 8 is a schematic diagram of the physical connection (actual deployment) of the communication system illustrated in Figure 7.
  • the gateway 702 of the example shown in FIG. 7 may be a WebSocket gateway, which interacts with a browser client by using a WebSocket protocol, and forwards the real-time interaction between the browser client and the back-end server through a TCP connection established by the browser client and the back-end server. information.
  • the gateway since the gateway establishes a TCP long connection with the browser client and the backend server, on the one hand, the browser client can implement full duplex communication with the backend server, and the real time information of the browser client The release time can be sent to the back-end server in real time, so the real-time performance is strong; on the other hand, the gateway is responsible for forwarding the user request message between the browser client and the back-end server through the TCP connection, and the main business logic and calculation are distributed in the Browser clients and back-end servers, the gateway does not need to undertake the main business logic and calculations, without the need to spend additional resources to achieve protocol conversion between HTTP and back-end servers, thus saving overhead.
  • the user request message sent by the browser client is received by the gateway and the transmission control protocol TCP connection of the browser client, where the user request message includes: an IP address and a port of the browser client;
  • the program may be stored in a computer readable storage medium, and the storage medium may include: Read only memory (ROM, Read Only Memory), random access memory (RAM), disk or optical disk.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The embodiments of the invention provide a method, gateway and communication system for a browser client directly communicating with a back-end server, in order to improve resource utilization while achieving end-to-end full-duplex communication between the browser client and the back-end server. The method comprises: receiving a user request message sent by the browser client through a transmission control protocol TCP connection between the gateway and the browser client; inquiring a message forwarding table according to the IP address and port of the browser client to obtain the IP address and port of the back-end server which are relevant to the IP address and port of the browser client; and sending the user request message to the back-end server corresponding to the IP address and port of the back-end server through the TCP connection between the gateway and the back-end server based on the IP address and port of the back-end server. The method provided by the invention achieves the protocol conversion between HTTP and the back-end server without consuming extra resources, thereby saves the expenses.

Description

浏览器客户端与后端 务器直通的方法、 网关和通信系统 技术领域 本发明涉及通信领域, 尤其涉及浏览器客户端与后端服务器直通的方法、 网关和通信系统。 背景技术 实时 Web是 Web2.0体系中的一类互联网应用,其典型代表主要包括互联 网的社交网站 Facebook和 twitter 。 在诸如社交网站 Facebook和 twitter 微博此类的实时 Web应用中,网站服务器需要实时地将用户好友的产出( Feed ) 信息主动推送给用户,使用户及其好友之间可以随时随地产生、分享和消费内 容。 其他诸如监控、 即时通信和即时报价系统等 Web应用也需要服务器将后 台发生的变化实时传送到客户端。 由此可知, 实时 Web应用的主要特征是高 交互性及实时性, 即非常需要在浏览器与后端服务器之间提供端到端的、双向 (全双工) 的实时通信。 现有的实现浏览器与后端服务器实时交互获取实时更新信息方法有基于 超文本传输协议(Hypertext Transfer Protocol, HTTP )轮询 (Polling )和基于 HTTP长连接的 "服务器推" 技术(即 Comet技术)等。 以下以基于 HTTP 轮询为例,说明现有技术提供的浏览器与后端服务器实时交互获取实时更新信 息方法, 包括如下步骤: S11 , 浏览器通过 Web连接到 Web应用服务器, 并基于 HTTP向 Web应 用服务器发送 HTTP请求; 512, Web应用服务器接收并解析浏览器的 HTTP请求, 将 HTTP请求转 换为对其扩展定制应用服务程序的调用; TECHNICAL FIELD The present invention relates to the field of communications, and in particular, to a method, a gateway, and a communication system for a browser client to communicate with a backend server. BACKGROUND Real-time Web is a kind of Internet application in the Web2.0 system, and its typical representative mainly includes the social networking websites Facebook and Twitter. In real-time web applications such as social networking sites Facebook and twitter microblogging, the web server needs to actively push the user's friend's output (feed) information to the user in real time, so that users and their friends can generate and share anytime, anywhere. And consumer content. Other web applications such as monitoring, instant messaging, and real-time quoting systems also require the server to deliver changes in the background to the client in real time. It can be seen that the main features of real-time web applications are high interactivity and real-time, that is, it is very necessary to provide end-to-end, two-way (full duplex) real-time communication between the browser and the back-end server. Existing methods for real-time interaction between the browser and the back-end server to obtain real-time update information are based on Hypertext Transfer Protocol (HTTP) polling (Polling) and HTTP server-based "server push" technology (ie Comet technology) )Wait. The following is an example of HTTP-based polling, which illustrates a method for real-time interaction between a browser provided by a prior art and a back-end server to obtain real-time update information, including the following steps: S11, the browser connects to the web application server through the web, and is based on HTTP to the web. The application server sends an HTTP request; 512. The web application server receives and parses the browser's HTTP request, and converts the HTTP request into a call to the extended custom application service program;
513 , 扩展定制应用服务程序解析 Web应用逻辑及协议, 并将这些 Web 应用逻辑及协议转换为对后端服务器的标准 API或者消息调用; S14, 扩展定制应用 良务程序调用相应的消息客户端程序, 例如, RSS513. The extended custom application service program parses the web application logic and protocol, and converts the web application logic and protocol into a standard API or message call to the backend server; and S14, the extended custom application service program invokes the corresponding message client program. , for example, RSS
( Really Simple Syndication )客户端、 JMS ( Java Message Service )客户端、 EJB ( Enterprise Java Bean )客户端或 XMPP ( The Extensible Messaging and Presence Protocol )客户端程序,建立一个全双工的 TCP/IP连接到后端服务器, 并基于相应的消息协议交互, 从后端服务器获取更新信息; S14, 浏览器基于 HTTP轮询向 Web服务器请求, 或者 Web服务器使用Really Simple Syndication client, JMS (Java Message Service) client, EJB (Enterprise Java Bean) client or XMPP (The Extensible Messaging and Presence Protocol) client program, establish a full-duplex TCP/IP connection to a backend server, and based on the corresponding message protocol interaction, obtaining update information from the backend server; S14, the browser requests the web server based on HTTP polling, or the web server uses
Comet技术将信息发送给浏览器显示。 上述现有技术提供的浏览器与后端服务器实时交互获取实时更新信息方 法中, 浏览器与 Web应用服务器之间的会话以及 Web应用服务器与后端服务 器之间的会话是完全独立和割裂的, 因此, 上述现有技术存在如下缺陷: 1 ) 资源浪费严重。 由于采用的 HTTP协议所承载的信息往往只有几个字 节, 而 HTTP头过大(近 1K ), 即无效信息载荷多, 因此, 频繁的轮询造成系 统带宽消耗大、 延迟高; Comet technology sends the information to the browser for display. In the method for real-time interaction between the browser and the back-end server to obtain real-time update information, the session between the browser and the web application server and the session between the web application server and the back-end server are completely independent and separated. Therefore, the above prior art has the following drawbacks: 1) The resource waste is serious. Since the information carried by the HTTP protocol is often only a few bytes, and the HTTP header is too large (nearly 1K), that is, there are many invalid information payloads. Therefore, frequent polling causes system bandwidth consumption and high latency;
2 )系统具有性能瓶頭。 由于浏览器与后端服务器之间的 Web服务器需要 运行主要的业务逻辑与计算, 因此, Web服务器的性能成为系统的性能瓶颈; 3 )无法实现端到端的全双工通信。 浏览器与 Web应用服务器之间通信是 基于 HTTP协议, 例如传统的 HTTP轮询或者 Comet技术, 以获取实时信息; 由于传统的 HTTP轮询是半双工, 基于 HTTP协议的 Comet技术需要在两条 连接上实现双向通信, 因此比较耗费服务器资源,在浏览器与后端服务器之间 无法 ^艮好地实现端到端的全双工的通信。 发明内容 2) The system has a performance bottle head. Since the web server between the browser and the back-end server needs to run the main business logic and calculation, the performance of the web server becomes the performance bottleneck of the system; 3) the end-to-end full-duplex communication cannot be realized. The communication between the browser and the web application server is Based on the HTTP protocol, such as the traditional HTTP polling or Comet technology, to obtain real-time information; since the traditional HTTP polling is half-duplex, the Comet technology based on the HTTP protocol needs to implement two-way communication on two connections, so it is more expensive to use the server. Resources, end-to-end full-duplex communication cannot be achieved between the browser and the back-end server. Summary of the invention
本发明实施例提供浏览器客户端与后端服务器直通的方法、网关和通信系 统,以在浏览器客户端与后端服务器之间实现端到端的全双工通信的同时提高 资源利用率。  Embodiments of the present invention provide a method, a gateway, and a communication system for a browser client to communicate with a backend server to achieve end-to-end full-duplex communication between a browser client and a backend server while improving resource utilization.
本发明实施例提供一种浏览器客户端与后端服务器直通的方法,所述方法 包括: 通过网关与浏览器客户端的传输控制协议 TCP连接接收浏览器客户端 发送的用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP地址 和端口;  An embodiment of the present invention provides a method for a browser client to communicate with a backend server. The method includes: receiving, by a gateway, a TCP control connection of a browser client, a user request message sent by a browser client, where the user The request message includes: an IP address and a port of the browser client;
根据所述浏览器客户端的 IP地址和端口查询消息转发表, 获得与所述浏 览器客户端的 IP地址和端口关联的后端良务器的 IP地址和端口;  Obtaining an IP address and a port of the backend server associated with the IP address and port of the browser client according to the IP address and port query message forwarding table of the browser client;
根据所述后端服务器的 IP地址和端口,通过网关与所述后端服务器的 TCP 连接将所述用户请求消息发送至与所述后端服务器的 IP地址和端口对应的后 端服务器。  And sending, according to the IP address and port of the backend server, the user request message to a backend server corresponding to the IP address and port of the backend server through a TCP connection of the gateway to the backend server.
本发明实施例提供一种网关, 所述网关包括:  An embodiment of the present invention provides a gateway, where the gateway includes:
接收模块, 用于通过网关与浏览器客户端的传输控制协议 TCP连接接收 浏览器客户端发送的用户请求消息, 所述用户请求消息包括: 所述浏览器客户 端的 IP地址和端口; 第一获取模块, 用于根据所述浏览器客户端的 IP地址和端口查询消息转 发表, 获得与所述浏览器客户端的 IP地址和端口关联的后端服务器的 IP地址 和端口; a receiving module, configured to receive, by using a gateway, a transmission control protocol (TCP) connection of the browser client, a user request message sent by the browser client, where the user request message includes: an IP address and a port of the browser client; a first obtaining module, configured to obtain, according to an IP address and a port query message forwarding table of the browser client, an IP address and a port of a backend server associated with an IP address and a port of the browser client;
发送模块, 用于根据所述后端服务器的 IP地址和端口, 通过网关与所述 后端服务器的 TCP连接将所述用户请求消息发送至与所述后端服务器的 IP地 址和端口对应的后端服务器。 本发明实施例提供一种通信系统, 所述通信系统包括: 浏览器客户端、 网 关和后端服务器; 所述浏览器客户端, 用于通过与所述网关的传输控制协议 TCP连接发送 用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP地址和端口; 所述网关, 用于通过与浏览器客户端的所述 TCP连接接收浏览器客户端 发送的所述用户请求消息; 根据所述用户请求消息中浏览器客户端的 IP地址 和端口查询消息转发表, 获得与所述浏览器客户端的 IP地址和端口关联的后 端服务器的 IP地址和端口; 根据所述后端服务器的 IP地址和端口, 通过与所 述后端服务器的 TCP连接将所述用户请求消息发送至与所述后端服务器的 IP 地址和端口对应的后端良务器; 所述后端服务器, 用于接收所述网关转发的用户请求消息。  a sending module, configured to send, by using a TCP connection between the gateway and the backend server, the user request message to the IP address and port corresponding to the backend server according to an IP address and a port of the backend server End server. An embodiment of the present invention provides a communication system, where the communication system includes: a browser client, a gateway, and a backend server; and the browser client is configured to send a user request by using a TCP connection with the gateway of the gateway. a message, the user request message includes: an IP address and a port of the browser client; the gateway, configured to receive, by using the TCP connection with a browser client, the user request message sent by a browser client; The user request message in the browser client's IP address and port query message forwarding table, obtain the IP address and port of the backend server associated with the browser client's IP address and port; according to the IP of the backend server An address and a port, the user request message is sent to a backend server corresponding to an IP address and a port of the backend server by a TCP connection with the backend server; the backend server is configured to receive User request message forwarded by the gateway.
从上述本发明实施例可知,由于网关与浏览器客户端以及后端服务器建立 的是 TCP长连接, 一方面, 浏览器客户端可以与后端服务器实现全双工通信, 浏览器客户端的实时信息几近发布时间就能实时发送到后端服务器,因此实时 性强; 另一方面, 网关通过 TCP连接负责转发浏览器客户端到后端服务器之 间的用户请求消息, 主要的业务逻辑与计算分布在浏览器客户端和后端服务 器, 网关不需要承担主要的业务逻辑与计算, 无需耗费额外资源实现 HTTP与 后端服务器之间的协议转换, 因此节省了开销。 As can be seen from the above embodiments of the present invention, since the gateway establishes a TCP long connection with the browser client and the backend server, on the one hand, the browser client can implement full duplex communication with the backend server, and the real time information of the browser client Nearly the release time can be sent to the back-end server in real time, so the real-time performance is strong; on the other hand, the gateway is responsible for forwarding the browser client to the back-end server through the TCP connection. The user request message, the main business logic and calculation are distributed in the browser client and the back-end server. The gateway does not need to undertake the main business logic and calculation, and does not need to use additional resources to realize the protocol conversion between the HTTP and the back-end server. This saves overhead.
附图说明 DRAWINGS
为了更清楚地说明本发明实施例的技术方案,下面将对现有技术或实施例 描述中所需要使用的附图作筒单地介绍,显而易见地, 下面描述中的附图仅仅 是本发明的一些实施例,对于本领域技术人员来讲,还可以如这些附图获得其 他的附图。  In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the prior art or the embodiments will be briefly described below. Obviously, the drawings in the following description are only the present invention. For some embodiments, other figures may also be obtained as those skilled in the art from these figures.
图 1是本发明实施例提供的浏览器客户端与后端服务器直通的方法流程 示意图;  1 is a schematic flowchart of a method for directly connecting a browser client and a backend server according to an embodiment of the present invention;
图 2是本发明实施例提供的浏览器客户端与后端服务器直通的方法中浏 览器客户端、 WebSocket网关和后端服务器之间的交互示意图;  2 is a schematic diagram of interaction between a browser client, a WebSocket gateway, and a backend server in a method in which a browser client and a backend server are directly connected according to an embodiment of the present invention;
图 3是本发明实施例提供的网关结构示意图;  3 is a schematic structural diagram of a gateway according to an embodiment of the present invention;
图 4是本发明另一实施例提供的网关结构示意图;  4 is a schematic structural diagram of a gateway according to another embodiment of the present invention;
图 5是本发明另一实施例提供的网关结构示意图;  FIG. 5 is a schematic structural diagram of a gateway according to another embodiment of the present invention;
图 6是本发明另一实施例提供的网关结构示意图;  6 is a schematic structural diagram of a gateway according to another embodiment of the present invention;
图 7本发明实施例提供的通信系统结构示意图;  FIG. 7 is a schematic structural diagram of a communication system according to an embodiment of the present invention;
图 8是本发明实施例提供的通信系统物理连接示意图。  FIG. 8 is a schematic diagram of a physical connection of a communication system according to an embodiment of the present invention.
具体实施方式 detailed description
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是 全部的实施例。基于本发明中的实施例, 本领域技术人员所获得的所有其他实 施例, 都属于本发明保护的范围。 The technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. It is obvious that the described embodiments are only a part of the embodiments of the present invention, instead of All embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention are within the scope of the present invention.
请参阅附图 1 , 是本发明实施例提供的浏览器客户端与后端服务器直通的 方法流程示意图。 附图 1示例的方法是以浏览器为网页 (Web )浏览器、 网关 是 WebSocket网关、 WebSocket网关与浏览器客户端、 后端服务器进行通信的 通信协议是 HTML5标准 WebSocket协议为例进行, 其执行主体可以是  1 is a schematic flowchart of a method for directly connecting a browser client and a backend server according to an embodiment of the present invention. The method illustrated in FIG. 1 is a communication protocol in which a browser is a web browser, a gateway is a Web socket gateway, a web socket gateway communicates with a browser client, and a back server is an HTML5 standard WebSocket protocol, and its execution is performed. The subject can be
WebSocket网关, 主要包括步骤: WebSocket gateway, mainly includes steps:
S101 , 通过网关与浏览器客户端的传输控制协议 TCP连接接收浏览器客 户端发送的用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP 地址和端口。  S101: Receive a user request message sent by the browser client by using a TCP control connection between the gateway and the browser client, where the user request message includes: an IP address and a port of the browser client.
可选地, 所述方法还可以包括: 通过网关与浏览器客户端的 TCP连接接 收浏览器客户端发送的握手请求消息,所述握手请求消息包含后端服务器的 IP 地址和端口;根据所述握手请求消息建立网关与所述后端服务器的 TCP连接; 将所述浏览器客户端的 IP地址、端口与所述后端服务器的 IP地址、端口关联, 并将所述关联关系更新到所述消息转发表中。其中, 所述根据所述握手请求消 息建立网关与所述后端服务器的 TCP连接可以为: 析取所述握手请求消息包 含的所述后端服务器的 IP地址和端口; 根据所述后端服务器的 IP地址和端口 建立网关与所述后端服务器的 TCP连接。  Optionally, the method may further include: receiving, by using a TCP connection between the gateway and the browser client, a handshake request message sent by the browser client, where the handshake request message includes an IP address and a port of the backend server; The request message establishes a TCP connection between the gateway and the backend server; associates an IP address and a port of the browser client with an IP address and a port of the backend server, and updates the association relationship to the message Published. The establishing a TCP connection between the gateway and the backend server according to the handshake request message may be: extracting an IP address and a port of the backend server included in the handshake request message; according to the backend server The IP address and port establish a TCP connection between the gateway and the backend server.
在本发明实施例中, 用户在访问网关时, 浏览器客户端向网关发送一个应 用程序下载请求, 从网关下载 Web应用程序到浏览器客户端。 此后, 用户为 了从后端服务器获取实时信息, 在浏览器客户端运行所述 Web应用程序以请 求与网关建立传输控制协议(Transmission Control Protocol, TCP )连接。 在浏览器客户端与网关的 TCP连接建立后,浏览器客户端可以通过该 TCP 连接向网关发送、 网关通过该 TCP接收用户请求消息, 例如, 订阅请求, 该 用户请求消息包含浏览器客户端的 IP地址和端口等表明信源的信息。 为了提 高浏览器客户端与网关之间消息传输的效率,在浏览器客户端与网关建立 TCP 连接后, 浏览器客户端可以向网关发送一个握手请求消息, 该握手请求消息是 基于 HTTP协议。 网关通过其与浏览器客户端的 TCP连接接收浏览器客户端 发送的握手请求消息。 当网关向浏览器客户端发送一个握手成功的响应消息 时, 浏览器客户端与网关之间协商成功,后续浏览器客户端与网关之间的交互 都是基于 WebSocket协议进行, WebSocket协议消息可通过该 TCP连接进行 传输。 由于 WebSocket协议消息的消息头 (Head ) 非常小即消息的开销小, 因此, 与现有技术中浏览器与 Web应用服务器采用 HTTP协议进行传输相比, 效率要高; 另一方面, 由于网关与浏览器客户端、 后端服务器进行通信的通信 协议是 HTML5标准 WebSocket协议而不是私有定制协议, 因此, 通用性好。 In the embodiment of the present invention, when the user accesses the gateway, the browser client sends an application download request to the gateway, and downloads the web application from the gateway to the browser client. Thereafter, in order to obtain real-time information from the backend server, the user runs the web application on the browser client to request to establish a Transmission Control Protocol (TCP) connection with the gateway. After the TCP connection between the browser client and the gateway is established, the browser client can send the gateway to the gateway through the TCP connection, and the gateway receives the user request message through the TCP, for example, a subscription request, where the user request message includes the IP of the browser client. Information such as address and port indicates the source. In order to improve the efficiency of message transmission between the browser client and the gateway, after the browser client establishes a TCP connection with the gateway, the browser client may send a handshake request message to the gateway, and the handshake request message is based on the HTTP protocol. The gateway receives the handshake request message sent by the browser client through its TCP connection with the browser client. When the gateway sends a response message to the browser client, the negotiation between the browser client and the gateway is successful. The interaction between the browser client and the gateway is based on the WebSocket protocol. The WebSocket protocol message can pass. The TCP connection is transmitted. Since the header of the WebSocket protocol message is very small, that is, the overhead of the message is small, it is more efficient than the transmission of the HTTP protocol by the browser and the web application server in the prior art; on the other hand, due to the gateway and The communication protocol for the browser client and the backend server to communicate is the HTML5 standard WebSocket protocol instead of the private custom protocol, so the versatility is good.
网关接收的握手请求消息可以包含后端服务器的 IP地址、 端口以及所述 后端服务器的通信协议等信息, 其中,后端服务器的通信协议是握手请求消息 中的可选项, 即握手请求消息可以不包含后端服务器的通信协议,后端服务器 的通信协议这一信息可以预先配置。 后端服务器的 IP地址、 端口以及所述后 端服务器的通信协议等信息可以通过在握手请求消息中新增信元而成,如下所 示, 是握手请求消息中新增信元的 HTTP Upgrade握手请求消息的示例:  The handshake request message received by the gateway may include information such as an IP address of the backend server, a port, and a communication protocol of the backend server, where the communication protocol of the backend server is an option in the handshake request message, that is, the handshake request message may be The communication protocol of the backend server is not included, and the communication protocol of the backend server can be preconfigured. The IP address of the backend server, the port, and the communication protocol of the backend server can be obtained by adding a cell to the handshake request message, as shown below, which is an HTTP Upgrade handshake of the newly added cell in the handshake request message. Example of a request message:
GET /realtime-info HTTP/1.1  GET /realtime-info HTTP/1.1
Upgrade: WebSocket  Upgrade: WebSocket
Connection: Upgrade Host: mysite.com Connection: Upgrade Host: mysite.com
Origin: http://mysite.com  Origin: http://mysite.com
DestHost: tcp:// myDestHostAddress:9960  DestHost: tcp:// myDestHostAddress: 9960
其中, 新增的信元 "DestHost: tcp:〃 myDestHostAddress:9960,, , 即用于 声明后端服务器的 IP地址、 端口以及所述后端服务器的通信协议, 本实施例 中, 后端服务器的通信协议是 TCP。  The new cell "DestHost: tcp: 〃 myDestHostAddress: 9960,," is used to declare the IP address of the backend server, the port, and the communication protocol of the backend server. In this embodiment, the backend server The communication protocol is TCP.
在接收到浏览器客户端发送的握手请求消息后,网关根据所述握手请求消 息建立其与后端服务器的 TCP连接。 具体地, 网关析取所述握手请求消息包 含的所述后端服务器的 IP地址和端口, 然后根据所述后端服务器的 IP地址和 端口建立网关至所述后端服务器的 TCP连接。  After receiving the handshake request message sent by the browser client, the gateway establishes its TCP connection with the backend server according to the handshake request message. Specifically, the gateway extracts an IP address and a port of the backend server included in the handshake request message, and then establishes a TCP connection of the gateway to the backend server according to the IP address and port of the backend server.
S102, 根据所述浏览器客户端的 IP地址和端口查询消息转发表, 获得与 所述浏览器客户端的 IP地址和端口关联的后端服务器的 IP地址、 端口。  S102. Query a message forwarding table according to the IP address and port of the browser client, and obtain an IP address and a port of the backend server associated with the IP address and port of the browser client.
在本发明实施例中, 网关维护一个消息转发表, 当有新的连接建立时, 网 关可以将该消息转发表进行更新。例如, 网关在收到握手请求消息并据此建立 网关至所述后端服务器的 TCP连接后, 可以更新消息转发表, 即, 记录所述 后端服务器的 IP地址、 端口、 所述后端服务器的通信协议以及所述浏览器客 户端的 IP地址和端口等信息。 在本发明实施中, 网关根据浏览器客户端发送 的握手请求消息建立网关与所述后端服务器的 TCP连接后, 将浏览器客户端 的 IP地址、 端口与后端良务器的 IP地址、 端口关联, 并将所述关联关系更新 到所述消息转发表中。 因此, 更新后的消息转发表包含所述后端服务器的 IP 地址、 端口、 所述后端服务器的通信协议以及所述浏览器客户端的 IP地址和 端口等信息, 并且可以记录所述浏览器客户端的 IP地址、 端口与所述后端月^ 务器的 IP地址、 端口关联关系。 消息转发表记录这些关联关系的意义在于, 根据浏览器客户端的 IP地址、 端口, 通过查询消息转发表, 可以获取与之关 联的后端服务器的 IP地址、 端口, 或者反之, 根据后端服务器的 IP地址、 端 口, 通过查询消息转发表, 可以获取与之关联的浏览器客户端的 IP地址、 端 口。 需要说明的是, 由于后端服务器可以广播 "建立连接请求" 消息, 因此, 网关也可以在侦听到这些广播的建立连接请求"消息后,建立与后端服务器的In the embodiment of the present invention, the gateway maintains a message forwarding table, and when a new connection is established, the gateway may update the message forwarding table. For example, after receiving the handshake request message and establishing a TCP connection of the gateway to the backend server, the gateway may update the message forwarding table, that is, record the IP address, port, and the backend server of the backend server. Communication protocol and information such as the IP address and port of the browser client. In the implementation of the present invention, after the gateway establishes a TCP connection between the gateway and the backend server according to the handshake request message sent by the browser client, the gateway sets the IP address of the browser client, the IP address of the port and the server of the backend server, and the port. Associating, and updating the association relationship to the message forwarding table. Therefore, the updated message forwarding table includes an IP address of the backend server, a port, a communication protocol of the backend server, and an IP address of the browser client. Information such as a port, and can record an IP address of the browser client, an IP address of the port and the backend server, and a port association relationship. The meaning of the message forwarding table recording these associations is that, according to the IP address and port of the browser client, by querying the message forwarding table, the IP address, port, or vice versa of the backend server associated with it can be obtained, according to the backend server. The IP address and port can be obtained by querying the message forwarding table to obtain the IP address and port of the browser client associated with it. It should be noted that since the backend server can broadcast the "establish connection request" message, the gateway can also establish the connection with the backend server after listening to the "establishment connection request" message of these broadcasts.
TCP连接, 本发明对网关建立与后端服务器的 TCP连接的方式可不做限制。 TCP connection, the present invention does not limit the manner in which the gateway establishes a TCP connection with the backend server.
S103, 根据后端服务器的 IP地址和端口, 通过网关与后端服务器的 TCP 连接将用户请求消息发送至与所述后端服务器的 IP地址和端口对应的后端服 务器。  S103. Send a user request message to the backend server corresponding to the IP address and port of the backend server by using a TCP connection between the gateway and the backend server according to the IP address and port of the backend server.
当用户通过浏览器客户端发送一个请求消息时,网关接收浏览器客户端发 送的请求消息。 由于在应用层以下的网络协议层(例如, IP层), 网关可以解 析出该请求消息包含的后端服务器的 IP地址、 端口、 后端服务器的通信协议, 因此, 网关可以查询所述更新后的消息转发表, 即, 网关根据浏览器客户端的 When the user sends a request message through the browser client, the gateway receives the request message sent by the browser client. Due to the network protocol layer (for example, the IP layer) below the application layer, the gateway can parse out the IP address of the back-end server included in the request message, the port, and the communication protocol of the back-end server. Therefore, the gateway can query the update. Message forwarding table, ie, the gateway is based on the browser client
IP地址、 端口查询消息转发表, 获得与所述浏览器客户端的 IP地址和端口关 联的后端服务器的的 IP地址和端口。 然后, 根据获取的所述后端服务器 IP地 址和端口, 将所述请求消息发送至与所述后端良务器的 IP地址和端口对应的 后端服务器, 从而实现通过所述网关与所述后端服务器的 TCP连接, 转发所 述浏览器客户端与所述后端服务器之间的交互的消息。 The IP address, port query message forwarding table, obtains the IP address and port of the backend server associated with the browser client's IP address and port. And sending, according to the obtained backend server IP address and port, the request message to a backend server corresponding to the IP address and port of the backend server, thereby implementing the gateway and the A TCP connection of the backend server, forwarding a message of interaction between the browser client and the backend server.
可选地, 本发明实施例提供的方法还可以包括: 通过网关与后端服务器的 TCP连接接收所述后端服务器发送的请求响应消息, 所述请求响应消息包括: 所述后端服务器的 IP地址和端口; 根据所述后端服务器的 IP地址和端口查询 所述消息转发表, 获得与所述后端服务器的 IP地址和端口关联的浏览器客户 端的 IP地址和端口; 根据所述浏览器客户端的 IP地址和端口, 通过网关与所 述浏览器客户端的 TCP连接将所述请求响应消息发送至与所述浏览器客户端 的 IP地址和端口对应的浏览器客户端。 Optionally, the method provided by the embodiment of the present invention may further include: using a gateway and a backend server The TCP connection receives the request response message sent by the backend server, where the request response message includes: an IP address and a port of the backend server; and querying the message forwarding table according to the IP address and port of the backend server, Obtaining an IP address and port of a browser client associated with the IP address and port of the backend server; and according to the IP address and port of the browser client, the request is made through a TCP connection between the gateway and the browser client The response message is sent to a browser client corresponding to the IP address and port of the browser client.
后端服务器接收到通过网关转发的请求消息时, 向网关发送请求响应消 息。 网关通过其与后端服务器的 TCP连接接收所述后端服务器发送的请求响 应消息, 该请求响应消息为对浏览器客户端发送的用户请求消息的响应, 其中 包含后端服务器的 IP地址和端口,还可以包含后端服务器的通信协议等信息。  When the backend server receives the request message forwarded through the gateway, it sends a request response message to the gateway. The gateway receives a request response message sent by the backend server through a TCP connection with the backend server, where the request response message is a response to a user request message sent by the browser client, where the IP address and port of the backend server are included. It can also contain information such as the communication protocol of the backend server.
由于在应用层以下的网络协议层(例如, IP层), 网关可以解析出该请求 响应消息包含的后端服务器的 IP地址、端口和后端服务器的通信协议等信息, 因此, 网关可以查询所述更新后的消息转发表, 即, 网关根据后端服务器的 IP 地址和端口, 查询所述更新后的消息转发表, 获取与所述后端服务器的 IP地 址、 端口关联的浏览器客户端的 IP地址、 端口。 然后, 根据获取的所述浏览 器客户端的 IP地址、 端口, 将所述请求响应消息转发至与所述浏览器客户端 的 IP地址和端口对应的浏览器客户端, 从而实现通过事前网关建立的与所述 浏览器客户端的 TCP连接, 转发所述浏览器客户端与所述后端服务器之间交 互的消息。  Due to the network protocol layer (for example, the IP layer) below the application layer, the gateway can parse out the IP address of the backend server included in the request response message, the communication protocol of the port and the backend server, etc., so the gateway can query the location. The updated message forwarding table, that is, the gateway queries the updated message forwarding table according to the IP address and port of the backend server, and obtains the IP of the browser client associated with the IP address and port of the backend server. Address, port. Then, the request response message is forwarded to a browser client corresponding to the IP address and port of the browser client according to the acquired IP address and port of the browser client, thereby implementing the establishment established by the front gateway. The TCP connection of the browser client forwards a message exchanged between the browser client and the backend server.
从上述本发明实施例提供的浏览器客户端与后端服务器直通的方法可知, 由于网关与浏览器客户端以及后端服务器可以建立的是 TCP长连接,一方面, 浏览器客户端可以与后端服务器实现全双工通信,浏览器客户端的实时信息几 近发布时间就能实时发送到后端服务器, 因此实时性强; 另一方面, 网关通过The method for the direct connection between the browser client and the backend server provided by the embodiment of the present invention can be seen that, since the gateway and the browser client and the backend server can establish a TCP long connection, on the one hand, the browser client can be followed by The end server implements full-duplex communication, and the real-time information of the browser client The release time can be sent to the backend server in real time, so the real-time performance is strong; on the other hand, the gateway passes
TCP连接负责转发浏览器客户端发送给后端服务器之间的用户请求消息,主要 的业务逻辑与计算分布在浏览器客户端和后端服务器,网关不需要承担主要的 业务逻辑与计算, 无需耗费额外资源实现 HTTP与后端服务器之间的协议转 换, 因此节省了开销。 The TCP connection is responsible for forwarding the user request message sent by the browser client to the back-end server. The main business logic and calculation are distributed among the browser client and the back-end server. The gateway does not need to undertake the main business logic and calculation, and does not need to consume. Additional resources enable protocol conversion between HTTP and the backend server, thus saving overhead.
以下以浏览器客户端、 WebSocket网关和后端服务器之间的交互, 并且浏 览器客户端通过建立的 TCP连接向 WebSocket网关发送消息订阅请求以请求 订阅新的消息为例, 进一步说明浏览器与后端服务器直通的方法,请参阅附图 2, 浏览器客户端、 WebSocket网关和后端服务器之间的交互主要包括:  The following is an interaction between the browser client, the WebSocket gateway, and the backend server, and the browser client sends a message subscription request to the WebSocket gateway through the established TCP connection to request to subscribe to the new message as an example, further explaining the browser and the latter. For the method of direct server connection, please refer to FIG. 2. The interaction between the browser client, the WebSocket gateway and the backend server mainly includes:
S201 , 浏览器客户端向 WebSocket网关发送 Web应用程序下载请求。 S201. The browser client sends a web application download request to the WebSocket gateway.
Web应用程序下载请求是在用户访问网关时,浏览器客户端在接收这一访 问请求后向 WebSocket网关发送。 The web application download request is that when the user accesses the gateway, the browser client sends the access request to the WebSocket gateway.
5202, WebSocket网关将 Web应用程序下载到浏览器客户端。  5202, The WebSocket gateway downloads the web application to the browser client.
5203, 浏览器客户端运行 Web应用程序。  5203, the browser client runs the web application.
S204, 浏览器客户端接收用户输入的实时信息请求消息。  S204. The browser client receives a real-time information request message input by the user.
S205 , 浏览器客户端通过 Web应用程序向 WebSocket网关发送握手请求 消息。  S205. The browser client sends a handshake request message to the WebSocket gateway through the web application.
在通信开始时,浏览器客户端可以向网关发送一个基于 HTTP格式的握手 请求消息,以请求与网关协商通信协议。该握手请求消息包含后端服务器的 IP 地址、 端口, 可选地, 还可以包含所述后端服务器的通信协议等。 后端服务器 的 IP地址、 端口, 可选地, 还可以包含所述后端服务器的通信协议等信息可 以通过在握手请求消息中新增信元而成, 以下是握手请求消息中新增信元的 HTTP Upgrade握手请求消息的示例: At the beginning of the communication, the browser client can send a handshake request message based on the HTTP format to the gateway to request to negotiate a communication protocol with the gateway. The handshake request message includes an IP address and a port of the backend server, and optionally, a communication protocol of the backend server, and the like. The IP address and port of the backend server may optionally include information such as a communication protocol of the backend server. In order to add a cell to the handshake request message, the following is an example of an HTTP Upgrade handshake request message for adding a new cell in the handshake request message:
GET /realtime-info HTTP/1.1  GET /realtime-info HTTP/1.1
Upgrade: WebSocket  Upgrade: WebSocket
Connection: Upgrade  Connection: Upgrade
Host: mysite.com  Host: mysite.com
Origin: http://mysite.com  Origin: http://mysite.com
DestHost: tcp:// myDestHostAddress:9960  DestHost: tcp:// myDestHostAddress: 9960
其中, 新增的信元 "DestHost: tcp:〃 myDestHostAddress:9960,,, 即用于声 明后端服务器的 IP地址、 端口以及所述后端服务器的通信协议, 本实施例中, 后端服务器的通信协议是 TCP。  The new cell "DestHost: tcp: 〃 myDestHostAddress: 9960," is used to declare the IP address of the backend server, the port, and the communication protocol of the backend server. In this embodiment, the backend server The communication protocol is TCP.
5206, WebSocket网关解析握手请求消息。  5206. The WebSocket gateway parses the handshake request message.
网关通过解析握手请求消息, 析取其中包含的所述后端服务器的 IP地址 和端口, 然后根据所述后端服务器的 IP地址和端口建立网关与所述后端服务 器的 TCP连接, 包括:  The gateway resolves the handshake request message, extracts the IP address and port of the backend server included therein, and then establishes a TCP connection between the gateway and the backend server according to the IP address and port of the backend server, including:
5207, WebSocket网关向后端服务器发送 TCP连接建立请求。  5207. The WebSocket gateway sends a TCP connection establishment request to the backend server.
5208, 后端服务器向 WebSocket网关返回响应消息。  5208, the backend server returns a response message to the WebSocket gateway.
5209, WebSocket网关更新消息转发表。  5209, WebSocket Gateway updates the message forwarding table.
即, WebSocket网关在消息转发表中记录所述后端服务器的 IP地址、 端 口、 所述后端服务器的通信协议以及所述浏览器客户端的 IP地址和端口等, 更新后的消息转发表包含所述后端服务器的 IP地址、 端口、 所述后端服务器 的通信协议以及所述浏览器客户端的 IP地址和端口等信息, 并且可以记录所 述浏览器客户端的 IP地址、端口与所述后端服务器的 IP地址、端口关联关系。 在本实施中,网关根据浏览器客户端发送的握手请求消息建立网关与所述后端 服务器的 TCP连接后, 将浏览器客户端的 IP地址、 端口与后端服务器的 IP 地址、 端口关联, 并将所述关联关系更新到所述消息转发表中。 因此, 更新后 的消息转发表包含所述后端服务器的 IP地址、 端口、 所述后端服务器的通信 协议以及所述浏览器客户端的 IP地址和端口等信息, 并且包含所述浏览器客 户端的 IP地址、 端口与所述后端良务器的 IP地址、 端口关联关系。 消息转发 表记录这些关联关系的意义在于, 根据浏览器客户端的 IP地址、 端口, 通过 查询消息转发表, 可以获取与之关联的后端服务器的 IP地址、 端口, 或者反 之, 根据后端服务器的 IP地址、 端口, 通过查询消息转发表, 可以获取与之 关联的浏览器客户端的 IP地址、 端口。 That is, the WebSocket gateway records the IP address of the backend server, the port, the communication protocol of the backend server, and the IP address and port of the browser client in the message forwarding table, and the updated message forwarding table includes The IP address, port, and the backend server of the backend server The communication protocol and the information such as the IP address and port of the browser client, and the IP address of the browser client, the IP address of the port and the backend server, and the port association relationship may be recorded. In this implementation, the gateway establishes a TCP connection between the gateway and the backend server according to the handshake request message sent by the browser client, and associates the IP address and port of the browser client with the IP address and port of the backend server, and Updating the association relationship to the message forwarding table. Therefore, the updated message forwarding table includes information such as an IP address of the backend server, a port, a communication protocol of the backend server, and an IP address and port of the browser client, and includes the browser client. The IP address and port are associated with the IP address and port of the backend server. The meaning of the message forwarding table recording these associations is that, according to the IP address and port of the browser client, by querying the message forwarding table, the IP address, port, or vice versa of the backend server associated with it can be obtained, according to the backend server. The IP address and port can be obtained by querying the message forwarding table to obtain the IP address and port of the browser client associated with it.
5210, WebSocket网关向浏览器客户端发送握手请求响应消息。  5210. The WebSocket gateway sends a handshake request response message to the browser client.
WebSocket网关向浏览器客户端发送的握手请求响应消息表明 WebSocket 网关与浏览器客户端以及后端服务器成功建立 TCP连接, 后续的浏览器客户 端与后端服务器的消息交互都可以通过该 TCP连接进行。  The handshake request response message sent by the WebSocket gateway to the browser client indicates that the WebSocket gateway successfully establishes a TCP connection with the browser client and the backend server, and subsequent message interaction between the browser client and the backend server can be performed through the TCP connection. .
5211 , 浏览器客户端向 WebSocket网关发送消息订阅请求。  5211. The browser client sends a message subscription request to the WebSocket gateway.
对于应用层以下的网络协议层, 例如, IP层, 该消息订阅请求包含所述 后端服务器的 IP地址、 端口和所述后端服务器的通信协议等信息。  For a network protocol layer below the application layer, for example, an IP layer, the message subscription request includes information such as an IP address of the backend server, a port, and a communication protocol of the backend server.
S212, WebSocket网关解析该消息订阅请求。  S212. The WebSocket gateway parses the message subscription request.
在应用层以下的网络协议层(例如, IP层), WebSocket网关可以解析出 该消息订阅请求包含的所述后端服务器的 IP地址、 端口和所述后端服务器的 通信协议等信息, 因此, WebSocket网关可以查询步骤 S209中更新后的消息 转发表, 即, WebSocket网关根据浏览器客户端的 IP地址和端口, 查询消息 转发表, 获得与所述浏览器客户端关联的后端服务器的 IP地址和端口。 The network protocol layer (for example, the IP layer) below the application layer, the WebSocket gateway can parse out The message subscription request includes information about the IP address of the backend server, the port, and the communication protocol of the backend server. Therefore, the WebSocket gateway can query the updated message forwarding table in step S209, that is, the WebSocket gateway browses according to the message. The IP address and port of the client, query the message forwarding table, and obtain the IP address and port of the backend server associated with the browser client.
S213, WebSocket网关向后端服务器发送消息订阅请求。  S213. The WebSocket gateway sends a message subscription request to the backend server.
WebSocket网关根据获取的后端服务器的 IP地址和端口, 将所述消息订 阅请求发送至与所述后端服务器的 IP地址和端口对应的后端服务器。  The WebSocket gateway sends the message subscription request to the backend server corresponding to the IP address and port of the backend server according to the obtained IP address and port of the backend server.
5214,后端月良务器向 WebSocket网关发送与消息订阅请求相应的请求响应 消息。  5214. The backend server sends a request response message corresponding to the message subscription request to the WebSocket gateway.
对于应用层以下的网络协议层, 例如, IP层, 与消息订阅请求相应的响 应消息包含后端服务器的 IP地址和端口,,还可以包含后端服务器的通信协议 等信息。  For the network protocol layer below the application layer, for example, the IP layer, the response message corresponding to the message subscription request includes the IP address and port of the backend server, and may also contain information such as the communication protocol of the backend server.
5215, WebSocket网关将后端服务器的响应消息转发至浏览器客户端。 5215. The WebSocket gateway forwards the response message of the backend server to the browser client.
5216, 后端服务器向 WebSocket网关发送更新消息。 5216. The backend server sends an update message to the WebSocket gateway.
该更新消息即为消息订阅请求所请求订阅的消息。  The update message is the message requested by the message subscription request.
5217, WebSocket网关解析与消息订阅请求相应的响应消息。  5217. The WebSocket gateway parses a response message corresponding to the message subscription request.
由于在应用层以下的网络协议层(例如, IP层), WebSocket网关可以解 析出与消息订阅请求相应的请求响应消息包含的所述后端服务器后端服务器 的 IP地址、 端口和后端服务器的通信协议等信息, 因此, WebSocket网关可 以查询步骤 S209中更新后的消息转发表, 即, WebSocket网关根据后端服务 器的 IP地址和端口, 查询所述更新后的消息转发表, 获取与所述后端服务器 关联的浏览器客户端的 IP地址、 端口。 Due to the network protocol layer (for example, the IP layer) below the application layer, the WebSocket gateway can parse the IP address, port, and backend server of the backend server backend server included in the request response message corresponding to the message subscription request. The information such as the communication protocol, the WebSocket gateway can query the updated message forwarding table in step S209, that is, the WebSocket gateway queries the updated message forwarding table according to the IP address and port of the backend server, and obtains the information forwarding table. Server The IP address and port of the associated browser client.
5218, WebSocket网关向浏览器客户端转发更新消息。  5218. The WebSocket gateway forwards the update message to the browser client.
WebSocket网关根据获取的与所述后端服务器关联的浏览器客户端的 IP 地址、 端口后, 通过浏览器客户端的 IP地址、 端口查询到相应的浏览器通信 连接, 将步骤 S216中后端服务器向 WebSocket网关发送的更新消息转发至与 所述浏览器客户端的 IP地址和端口对应的浏览器客户端。  The WebSocket gateway queries the corresponding browser communication connection through the IP address and port of the browser client according to the obtained IP address and port of the browser client associated with the backend server, and sends the backend server to the WebSocket in step S216. The update message sent by the gateway is forwarded to the browser client corresponding to the IP address and port of the browser client.
5219, 浏览器客户端向 WebSocket网关发送与更新消息相应的响应消息。 该响应消息是对 WebSocket网关转发的更新消息的确认。  5219. The browser client sends a response message corresponding to the update message to the WebSocket gateway. The response message is an acknowledgment of the update message forwarded by the WebSocket gateway.
5220, WebSocket网关将与更新消息相应的响应消息发送至后端服务器。 请参阅附图 3, 是本发明实施例提供的网关结构示意图。 为了便于说明, 仅仅示出了与本发明实施例相关的部分。 附图 3示例的网关可以是 WebSocket 网关, 其与浏览器客户端、 后端服务器进行通信的通信协议可以是 HTML5标 准 WebSocket协议。 附图 3示例的网关包括接收模块 301、 第一获取模块 302 和发送模块 303, 其中:  5220. The WebSocket gateway sends a response message corresponding to the update message to the backend server. Referring to FIG. 3, it is a schematic diagram of a gateway structure provided by an embodiment of the present invention. For the convenience of description, only parts related to the embodiment of the present invention are shown. The gateway illustrated in Figure 3 may be a WebSocket gateway, and the communication protocol for communicating with the browser client and the backend server may be the HTML5 standard WebSocket protocol. The gateway illustrated in FIG. 3 includes a receiving module 301, a first obtaining module 302, and a transmitting module 303, where:
接收模块 301 ,用于通过网关与浏览器客户端的传输控制协议 TCP连接接 收浏览器客户端发送的用户请求消息, 所述用户请求消息包括: 所述浏览器客 户端的 IP地址和端口;  The receiving module 301 is configured to receive, by using a gateway and a transmission control protocol TCP connection of the browser client, a user request message sent by the browser client, where the user request message includes: an IP address and a port of the browser client;
第一获取模块 302, 用于根据所述浏览器客户端的 IP地址和端口查询消 息转发表, 获得与所述浏览器客户端的 IP地址和端口关联的后端服务器的 IP 地址和端口;  The first obtaining module 302 is configured to query the message forwarding table according to the IP address and port of the browser client, and obtain an IP address and a port of the backend server associated with the IP address and port of the browser client.
发送模块 303, 用于根据所述后端服务器的 IP地址和端口, 通过网关与 所述后端服务器的 TCP连接将所述用户请求消息发送至与所述后端服务器的 IP地址和端口对应的后端 务器。 a sending module 303, configured to use, according to the IP address and port of the backend server, by using a gateway The TCP connection of the backend server sends the user request message to a backend server corresponding to the IP address and port of the backend server.
当用户通过浏览器客户端发送一个请求消息时,接收模块 301接收浏览器 客户端发送的请求消息。 由于在应用层以下的网络协议层(例如, IP层), 网 关可以解析出该请求消息包含的后端服务器的 IP地址、 端口、 后端服务器的 通信协议, 因此, 第一获取模块 302可以查询所述更新后的消息转发表, 即, 第一获取模块 302根据浏览器客户端的 IP地址、 端口查询消息转发表, 获得 与所述浏览器客户端的 IP地址和端口关联的后端服务器的的 IP地址和端口。 然后, 发送模块 303根据获取的所述后端服务器 IP地址和端口, 将所述请求 消息发送至与所述后端服务器的 IP地址和端口对应的后端服务器, 从而实现 通过所述网关与所述后端服务器的 TCP连接, 转发所述浏览器客户端与所述 后端服务器之间的交互的消息。  When the user sends a request message through the browser client, the receiving module 301 receives the request message sent by the browser client. Because the network protocol layer (for example, the IP layer) below the application layer can parse the IP address of the back-end server included in the request message, the port, and the communication protocol of the back-end server, the first obtaining module 302 can query The updated message forwarding table, that is, the first obtaining module 302 obtains the IP of the backend server associated with the IP address and port of the browser client according to the IP address of the browser client and the port query message forwarding table. Address and port. Then, the sending module 303 sends the request message to the backend server corresponding to the IP address and port of the backend server according to the obtained backend server IP address and port, thereby implementing the gateway and the A TCP connection of the backend server, forwarding a message of interaction between the browser client and the backend server.
从上述本发明实施例提供的网关可知,由于网关与浏览器客户端以及后端 服务器可以建立的是 TCP长连接, 一方面, 浏览器客户端可以与后端服务器 实现全双工通信,浏览器客户端的实时信息几近发布时间就能实时发送到后端 服务器, 因此实时性强; 另一方面, 网关通过 TCP连接负责转发浏览器客户 端发送给后端服务器之间的用户请求消息,主要的业务逻辑与计算分布在浏览 器客户端和后端服务器, 网关不需要承担主要的业务逻辑与计算, 无需耗费额 外资源实现 HTTP与后端服务器之间的协议转换, 因此节省了开销。  According to the gateway provided by the foregoing embodiment of the present invention, since the gateway and the browser client and the backend server can establish a TCP long connection, on the one hand, the browser client can implement full duplex communication with the backend server, and the browser The real-time information of the client can be sent to the back-end server in real time near the release time, so the real-time performance is strong; on the other hand, the gateway is responsible for forwarding the user request message sent by the browser client to the back-end server through the TCP connection, the main Business logic and calculations are distributed across browser clients and back-end servers. The gateway does not need to undertake major business logic and calculations, and does not require additional resources to implement protocol conversion between HTTP and back-end servers, thus saving overhead.
需要说明的是,以上网关的实施方式中,各功能模块的划分仅是举例说明, 实际应用中可以根据需要,例如相应硬件的配置要求或者软件的实现的便利考 虑, 而将上述功能分配由不同的功能模块完成, 即将所述网关的内部结构划分 成不同的功能模块,以完成以上描述的全部或者部分功能。而且,实际应用中, 本实施例中的相应的功能模块可以是由相应的硬件实现,也可以由相应的硬件 执行相应的软件完成, 例如, 前述的接收模块, 可以是具有执行前述通过网关 与浏览器客户端的传输控制协议 TCP连接接收浏览器客户端发送的用户请求 消息的硬件, 例如接收器,也可以是能够执行相应计算机程序从而完成前述功 能的一般处理器或者其他硬件设备; 再如前述的第一获取模块, 可以是具有执 行前述将根据所述浏览器客户端的 IP地址和端口查询消息转发表, 获得与所 述浏览器客户端的 IP地址和端口关联的后端服务器的 IP地址和端口功能的硬 件, 例如第一获取器,也可以是能够执行相应计算机程序从而完成前述功能的 一般处理器或者其他硬件设备(本说明书提供的各个实施例都可应用上述描述 原则)。 在附图 3示例的网关可以进一步包括握手消息接收模块 401、 连接建 立模块 402和更新模块 403, 如附图 4所示本发明另一实施例提供的网关, 其 中: It should be noted that, in the implementation manner of the foregoing gateway, the division of each functional module is only an example. In actual applications, the foregoing functional allocation may be different according to requirements, such as configuration requirements of corresponding hardware or convenience of implementation of software. The functional module is completed, that is, the internal structure of the gateway is divided. Different functional modules to complete all or part of the functions described above. Moreover, in practical applications, the corresponding functional modules in this embodiment may be implemented by corresponding hardware, or may be executed by corresponding hardware. For example, the foregoing receiving module may have the foregoing The transmission control protocol TCP connection of the browser client receives the hardware of the user request message sent by the browser client, such as a receiver, or a general processor or other hardware device capable of executing the corresponding computer program to perform the foregoing functions; The first obtaining module may be configured to execute the foregoing to forward the table according to the IP address and port query message of the browser client, and obtain the IP address and port of the backend server associated with the IP address and port of the browser client. The functional hardware, such as the first acquirer, may also be a general processor or other hardware device capable of executing a corresponding computer program to perform the aforementioned functions (the various embodiments provided herein may apply the above described principles). The gateway illustrated in FIG. 3 may further include a handshake message receiving module 401, a connection establishing module 402, and an update module 403. As shown in FIG. 4, a gateway provided by another embodiment of the present invention, wherein:
握手消息接收模块 401 ,用于通过网关与浏览器客户端的 TCP连接接收浏 览器客户端发送的握手请求消息, 所述握手请求消息包含后端服务器的 IP地 址和端口;  The handshake message receiving module 401 is configured to receive, by using a TCP connection between the gateway and the browser client, a handshake request message sent by the browser client, where the handshake request message includes an IP address and a port of the backend server;
为了提高浏览器客户端与网关之间消息传输的效率,在浏览器客户端与网 关建立 TCP连接后, 浏览器客户端可以向网关发送一个握手请求消息, 该握 手请求消息是基于 HTTP协议。握手消息接收模块 401通过网关与浏览器客户 端的 TCP连接接收浏览器客户端发送的握手请求消息。 当网关向浏览器客户 端发送一个握手成功的响应消息时, 浏览器客户端与网关之间协商成功,后续 浏览器客户端与网关之间的交互都是基于 WebSocket协议进行, WebSocket协 议消息可通过该 TCP连接进行传输。由于 WebSocket协议消息的消息头( Head ) 非常小即消息的开销小, 因此, 与现有技术中浏览器与 Web应用服务器采用 HTTP协议进行传输相比, 效率要高; 另一方面, 由于网关与浏览器客户端、 后端服务器进行通信的通信协议是 HTML5标准 WebSocket协议而不是私有定 制协议, 因此, 通用性好。 In order to improve the efficiency of message transmission between the browser client and the gateway, after the browser client establishes a TCP connection with the gateway, the browser client may send a handshake request message to the gateway, and the handshake request message is based on the HTTP protocol. The handshake message receiving module 401 receives the handshake request message sent by the browser client through the TCP connection between the gateway and the browser client. When the gateway sends a response message to the browser client, the negotiation between the browser client and the gateway is successful. The interaction between the browser client and the gateway is based on the WebSocket protocol. The message can be transmitted over the TCP connection. Since the header of the WebSocket protocol message is very small, that is, the overhead of the message is small, it is more efficient than the transmission of the HTTP protocol by the browser and the web application server in the prior art; on the other hand, due to the gateway and The communication protocol for the browser client and the backend server to communicate is the HTML5 standard WebSocket protocol instead of the private custom protocol, so the versatility is good.
握手消息接收模块 401接收的握手请求消息可以包含后端服务器的 IP地 址、 端口以及所述后端服务器的通信协议等信息, 其中, 后端服务器的通信协 议是握手请求消息中的可选项,即握手请求消息可以不包含后端服务器的通信 协议, 后端服务器的通信协议这一信息可以预先配置。 后端服务器的 IP地址、 端口以及所述后端服务器的通信协议等信息可以通过在握手请求消息中新增 信元而成, 如下所示, 是握手请求消息中新增信元的 HTTP Upgrade握手请求 消息的示例:  The handshake request message received by the handshake message receiving module 401 may include information such as an IP address of the backend server, a port, and a communication protocol of the backend server, where the communication protocol of the backend server is an option in the handshake request message, that is, The handshake request message may not include the communication protocol of the backend server, and the information of the communication protocol of the backend server may be pre-configured. The IP address of the backend server, the port, and the communication protocol of the backend server can be obtained by adding a cell to the handshake request message, as shown below, which is an HTTP Upgrade handshake of the newly added cell in the handshake request message. Example of a request message:
GET /realtime-info HTTP/1.1  GET /realtime-info HTTP/1.1
Upgrade: WebSocket  Upgrade: WebSocket
Connection: Upgrade  Connection: Upgrade
Host: mysite.com  Host: mysite.com
Origin: http://mysite.com  Origin: http://mysite.com
DestHost: tcp:// myDestHostAddress:9960  DestHost: tcp:// myDestHostAddress: 9960
其中, 新增的信元 "DestHost: tcp:〃 myDestHostAddress:9960,, , 即用于 声明后端服务器的 IP地址、 端口以及所述后端服务器的通信协议, 本实施例 中, 后端服务器的通信协议是 TCP。 连接建立模块 402, 用于根据所述握手请求消息建立网关与所述后端服务 器的 TCP连接; The new cell "DestHost: tcp: 〃 myDestHostAddress: 9960,," is used to declare the IP address of the backend server, the port, and the communication protocol of the backend server. In this embodiment, the backend server The communication protocol is TCP. a connection establishing module 402, configured to establish, according to the handshake request message, a TCP connection between the gateway and the backend server;
更新模块 403, 用于将所述浏览器客户端的 IP地址、 端口与所述后端服 务器的 IP地址、 端口关联, 并将所述关联关系更新到所述消息转发表中。 附 图 3示例的网关可以进一步包括响应消息接收模块 501、 第二获取模块 502和 响应消息发送模块 503, 如附图 5所示本发明另一实施例提供的网关, 其中: 响应消息接收模块 501 ,用于通过网关与后端服务器的 TCP连接接收所述 后端服务器发送的请求响应消息, 所述请求响应消息包括: 所述后端服务器的 IP地址和端口;  The update module 403 is configured to associate an IP address and a port of the browser client with an IP address and a port of the backend server, and update the association relationship into the message forwarding table. The gateway illustrated in FIG. 3 may further include a response message receiving module 501, a second obtaining module 502, and a response message sending module 503. As shown in FIG. 5, the gateway provided by another embodiment of the present invention, where: the response message receiving module 501 Receiving a request response message sent by the backend server by using a TCP connection between the gateway and the backend server, where the request response message includes: an IP address and a port of the backend server;
第二获取模块 502, 用于根据所述后端服务器的 IP地址和端口查询所述 消息转发表, 获得与所述后端服务器的 IP地址和端口关联的浏览器客户端的 IP地址和端口;  The second obtaining module 502 is configured to query the message forwarding table according to the IP address and port of the backend server, and obtain an IP address and a port of a browser client associated with an IP address and a port of the backend server;
响应消息发送模块 503, 用于根据所述浏览器客户端的 IP地址和端口, 通过网关与所述浏览器客户端的 TCP连接将所述请求响应消息发送至与所述 浏览器客户端的 IP地址和端口对应的浏览器客户端。  The response message sending module 503 is configured to send the request response message to the IP address and port of the browser client by using a TCP connection between the gateway and the browser client according to the IP address and port of the browser client. The corresponding browser client.
应当理解的是,附图 4示例的网关也可以进一步包括如附图 5所示的响应 消息接收模块 501、第二获取模块 502以及响应消息发送模块 503 , 功能如上, 在此不再赘述。  It should be understood that the gateway illustrated in FIG. 4 may further include a response message receiving module 501, a second obtaining module 502, and a response message sending module 503 as shown in FIG. 5, and the functions are as described above, and details are not described herein again.
在本发明实施例中, 网关维护一个消息转发表, 当有新的连接建立时, 更 新模块 403可以将该消息转发表进行更新。例如, 连接建立模块 402在收到握 手请求消息并据此建立网关至所述后端服务器的 TCP连接后, 更新模块 403 可以更新消息转发表, 即, 记录所述后端服务器的 IP地址、 端口、 所述后端 服务器的通信协议以及所述浏览器客户端的 IP地址和端口等信息。 在本发明 实施中,连接建立模块 402根据浏览器客户端发送的握手请求消息建立网关与 所述后端服务器的 TCP连接后, 更新模块 403将浏览器客户端的 IP地址、 端 口与后端服务器的 IP地址、 端口关联, 并将所述关联关系更新到所述消息转 发表中。 因此, 更新后的消息转发表包含所述后端服务器的 IP地址、 端口、 所述后端服务器的通信协议以及所述浏览器客户端的 IP地址和端口等信息, 并且可以记录所述浏览器客户端的 IP地址、端口与所述后端服务器的 IP地址、 端口关联关系。 消息转发表记录的关联关系的意义在于, 第一获耳 ^莫块 302 根据浏览器客户端的 IP地址、 端口, 通过查询消息转发表, 可以获取与之关 联的后端服务器的 IP地址、 端口, 或者反之, 第二获取模块 502根据后端服 务器的 IP地址、 端口, 通过查询消息转发表, 可以获取与之关联的浏览器客 户端的 IP地址、 端口。 In the embodiment of the present invention, the gateway maintains a message forwarding table, and when a new connection is established, the update module 403 may update the message forwarding table. For example, after the connection establishment module 402 receives the handshake request message and establishes a TCP connection of the gateway to the backend server, the update module 403 The message forwarding table may be updated, that is, the IP address of the backend server, the port, the communication protocol of the backend server, and the IP address and port of the browser client are recorded. In the implementation of the present invention, after the connection establishment module 402 establishes a TCP connection between the gateway and the backend server according to the handshake request message sent by the browser client, the update module 403 sets the IP address, port and backend server of the browser client. The IP address, port association, and update the association relationship to the message forwarding table. Therefore, the updated message forwarding table includes information such as an IP address of the backend server, a port, a communication protocol of the backend server, and an IP address and port of the browser client, and may record the browser client. The IP address and port of the terminal are associated with the IP address and port of the backend server. The meaning of the association relationship recorded by the message forwarding table is that the first ear module 302 can obtain the IP address and port of the backend server associated with it by querying the message forwarding table according to the IP address and port of the browser client. Or vice versa, the second obtaining module 502 can obtain the IP address and port of the browser client associated with the message forwarding table according to the IP address and port of the backend server.
在附图 4示例的网关中, 连接建立模块 402可以进一步包括解析单元 601 和建立单元 602, 如附图 6所示本发明另一实施例提供的网关, 其中:  In the gateway illustrated in FIG. 4, the connection establishing module 402 may further include a parsing unit 601 and an establishing unit 602, such as the gateway provided by another embodiment of the present invention, as shown in FIG.
解析单元 601用于析取所述握手请求消息包含的所述后端服务器的 IP地 址和端口;  The parsing unit 601 is configured to extract an IP address and a port of the backend server included in the handshake request message;
建立单元 602, 用于根据所述后端服务器的 IP地址和端口建立网关与所 述后端服务器的 TCP连接。  The establishing unit 602 is configured to establish a TCP connection between the gateway and the backend server according to the IP address and port of the backend server.
请参阅附图 7, 本发明实施例提供的一种通信系统。 为了便于说明, 仅仅 示出了与本发明实施例相关的部分。附图 7示例的通信系统包括浏览器客户端 701、 后端服务器 703和附图 3至附图 6任一示例的网关 702, 其中: 浏览器客户端 701用于, 用于通过与所述网关的传输控制协议 TCP连接 发送用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP地址和 端口; Referring to FIG. 7, a communication system provided by an embodiment of the present invention. For the convenience of description, only parts related to the embodiment of the present invention are shown. The communication system illustrated in FIG. 7 includes a browser client 701, a backend server 703, and a gateway 702 of any of FIGS. 3 through 6, wherein: The browser client 701 is configured to send, by using a transmission control protocol TCP connection with the gateway, a user request message, where the user request message includes: an IP address and a port of the browser client;
网关 702,用于用于通过与浏览器客户端的所述 TCP连接接收浏览器客户 端发送的所述用户请求消息; 根据所述用户请求消息中浏览器客户端的 IP地 址和端口查询消息转发表, 获得与所述浏览器客户端的 IP地址和端口关联的 后端服务器的 IP地址和端口; 根据所述后端服务器的 IP地址和端口, 通过与 所述后端服务器的 TCP连接将所述用户请求消息发送至与所述后端服务器的 IP地址和端口对应的后端良务器;  The gateway 702 is configured to receive, by using the TCP connection with the browser client, the user request message sent by the browser client, according to the IP address and the port query message forwarding table of the browser client in the user request message, Obtaining an IP address and a port of the backend server associated with the IP address and port of the browser client; according to the IP address and port of the backend server, the user request is made through a TCP connection with the backend server Sending a message to a backend server corresponding to the IP address and port of the backend server;
后端服务器 703, 用于接收所述网关转发的用户请求消息。  The backend server 703 is configured to receive a user request message forwarded by the gateway.
在附图 7示例的通信系统中, 浏览器客户端 701还用于通过与所述网关 702的 TCP连接发送握手请求消息,所述握手请求消息包含所述后端服务器的 IP地址和端口; 所述网关 702还用于通过与所述浏览器客户端 701的 TCP连 接接收所述浏览器客户端 701发送的所述握手请求消息;根据所述握手请求消 息建立与所述后端服务器 703的所述 TCP连接; 将所述浏览器客户端 701的 IP地址、 端口与所述后端服务器的 IP地址、 端口关联, 并将所述关联关系更 新到所述消息转发表中。  In the communication system illustrated in FIG. 7, the browser client 701 is further configured to send a handshake request message by using a TCP connection with the gateway 702, where the handshake request message includes an IP address and a port of the backend server; The gateway 702 is further configured to receive, by using a TCP connection with the browser client 701, the handshake request message sent by the browser client 701; and establish a session with the backend server 703 according to the handshake request message. Describe the TCP connection; associate the IP address and port of the browser client 701 with the IP address and port of the backend server, and update the association relationship to the message forwarding table.
在附图 7示例的通信系统中, 后端服务器 703还用于通过与所述网关 702 的 TCP连接向所述网关 702发送请求响应消息, 所述请求响应消息包括: 所 述后端服务器的 IP地址和端口; 所述网关 702还用于通过与所述后端服务器 的 TCP连接接收所述后端服务器 703发送的请求响应消息; 根据所述请求响 应消息中的后端服务器 703的 IP地址和端口查询所述消息转发表, 获得与所 述后端良务器 703的 IP地址和端口关联的浏览器客户端 701的 IP地址和端口; 才艮据所述浏览器客户端 701的 IP地址和端口, 通过与所述浏览器客户端 701 的 TCP连接将所述请求响应消息发送至与所述浏览器客户端 701的 IP地址和 端口对应的浏览器客户端; 所述浏览器客户端 701还用于: 接收所述网关发送 的所述请求响应消息。 In the communication system illustrated in FIG. 7, the backend server 703 is further configured to send a request response message to the gateway 702 through a TCP connection with the gateway 702, where the request response message includes: an IP of the backend server The gateway 702 is further configured to receive, by using a TCP connection with the backend server, a request response message sent by the backend server 703; according to the IP address of the backend server 703 in the request response message The port queries the message forwarding table, obtains the location The IP address of the backend server 703 and the IP address and port of the browser client 701 associated with the port; according to the IP address and port of the browser client 701, through the browser client 701 The TCP connection sends the request response message to a browser client corresponding to the IP address and port of the browser client 701; the browser client 701 is further configured to: receive the Request response message.
附图 8是附图 7示例的通信系统物理连接(实际部署)示意图。 附图 7 示例的网关 702可以是 WebSocket网关,采用 WebSocket协议与浏览器客户端 交互, 通过浏览器客户端、 后端服务器建立的 TCP连接, 转发浏览器客户端 与后端服务器之间交互的实时信息。  Figure 8 is a schematic diagram of the physical connection (actual deployment) of the communication system illustrated in Figure 7. The gateway 702 of the example shown in FIG. 7 may be a WebSocket gateway, which interacts with a browser client by using a WebSocket protocol, and forwards the real-time interaction between the browser client and the back-end server through a TCP connection established by the browser client and the back-end server. information.
从上述本发明实施可知,由于网关与浏览器客户端以及后端服务器建立的 是 TCP长连接, 一方面, 浏览器客户端可以与后端服务器实现全双工通信, 浏览器客户端的实时信息几近发布时间就能实时发送到后端服务器,因此实时 性强; 另一方面, 网关通过 TCP连接负责转发浏览器客户端到后端服务器之 间的用户请求消息, 主要的业务逻辑与计算分布在浏览器客户端和后端服务 器, 网关不需要承担主要的业务逻辑与计算, 无需耗费额外资源实现 HTTP与 后端服务器之间的协议转换, 因此节省了开销。  As can be seen from the implementation of the present invention, since the gateway establishes a TCP long connection with the browser client and the backend server, on the one hand, the browser client can implement full duplex communication with the backend server, and the real time information of the browser client The release time can be sent to the back-end server in real time, so the real-time performance is strong; on the other hand, the gateway is responsible for forwarding the user request message between the browser client and the back-end server through the TCP connection, and the main business logic and calculation are distributed in the Browser clients and back-end servers, the gateway does not need to undertake the main business logic and calculations, without the need to spend additional resources to achieve protocol conversion between HTTP and back-end servers, thus saving overhead.
需要说明的是, 上述装置各模块 /单元之间的信息交互、 执行过程等内容, 由于与本发明方法实施例基于同一构思,其带来的技术效果与本发明方法实施 例相同, 具体内容可参见本发明方法实施例中的叙述, 此处不再赘述。  It should be noted that the information interaction, the execution process, and the like between the modules/units of the foregoing device are the same as the embodiment of the method of the present invention. Reference is made to the description in the method embodiment of the present invention, and details are not described herein again.
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步 骤是可以通过程序来指令相关的硬件来完成,比如以下各种方法的一种或多种 或全部: 通过网关与浏览器客户端的传输控制协议 TCP连接接收浏览器客户端发 送的用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP地址和 端口; One of ordinary skill in the art will appreciate that all or part of the various steps of the above-described embodiments may be performed by a program to instruct related hardware, such as one or more or all of the following various methods: The user request message sent by the browser client is received by the gateway and the transmission control protocol TCP connection of the browser client, where the user request message includes: an IP address and a port of the browser client;
根据所述浏览器客户端的 IP地址和端口查询消息转发表, 获得与所述浏 览器客户端的 IP地址和端口关联的后端良务器的 IP地址和端口;  Obtaining an IP address and a port of the backend server associated with the IP address and port of the browser client according to the IP address and port query message forwarding table of the browser client;
根据所述后端服务器的 IP地址和端口,通过网关与所述后端服务器的 TCP 连接将所述用户请求消息发送至与所述后端服务器的 IP地址和端口对应的后 端服务器。  And sending, according to the IP address and port of the backend server, the user request message to a backend server corresponding to the IP address and port of the backend server through a TCP connection of the gateway to the backend server.
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步 骤是可以通过程序来指令相关的硬件来完成,该程序可以存储于一计算机可读 存储介质中, 存储介质可以包括: 只读存储器(ROM, Read Only Memory ), 随机存取存储器(RAM, Random Access Memory ), 磁盘或光盘等。  A person skilled in the art may understand that all or part of the various steps of the foregoing embodiments may be completed by a program instructing related hardware. The program may be stored in a computer readable storage medium, and the storage medium may include: Read only memory (ROM, Read Only Memory), random access memory (RAM), disk or optical disk.
以上对本发明实施例提供的浏览器客户端与后端服务器直通的方法、网关 式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思 想; 同时, 对于本领域的一般技术人员, 依据本发明的思想, 在具体实施方式 及应用范围上均会有改变之处, 综上所述, 本说明书内容不应理解为对本发明 的限制。  The method and gateway type of the browser client and the back-end server provided by the embodiment of the present invention are described above. The description of the above embodiments is only for helping to understand the method and core idea of the present invention; The present invention is not limited by the scope of the present invention, and the details of the present invention are not limited by the scope of the present invention.

Claims

权 利 要 求 Rights request
1、 一种浏览器客户端与后端服务器直通的方法, 其特征在于, 所述方法 包括:  A method for directly connecting a browser client to a backend server, wherein the method comprises:
通过网关与浏览器客户端的传输控制协议 TCP连接接收浏览器客户端发 送的用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP地址和 端口;  And receiving, by the gateway and the browser client, a TCP connection, a user request message sent by the browser client, where the user request message includes: an IP address and a port of the browser client;
根据所述浏览器客户端的 IP地址和端口查询消息转发表, 获得与所述浏 览器客户端的 IP地址和端口关联的后端良务器的 IP地址和端口;  Obtaining an IP address and a port of the backend server associated with the IP address and port of the browser client according to the IP address and port query message forwarding table of the browser client;
根据所述后端服务器的 IP地址和端口,通过网关与所述后端服务器的 TCP 连接将所述用户请求消息发送至与所述后端服务器的 IP地址和端口对应的后 端服务器。  And sending, according to the IP address and port of the backend server, the user request message to a backend server corresponding to the IP address and port of the backend server through a TCP connection of the gateway to the backend server.
2、 根据权利要求 1所述的方法, 其特征在于, 所述方法还包括: 通过网关与浏览器客户端的 TCP连接接收浏览器客户端发送的握手请求 消息, 所述握手请求消息包含后端服务器的 IP地址和端口;  The method according to claim 1, wherein the method further comprises: receiving, by using a TCP connection between the gateway and the browser client, a handshake request message sent by the browser client, where the handshake request message includes a backend server IP address and port;
根据所述握手请求消息建立网关与所述后端服务器的 TCP连接; 将所述浏览器客户端的 IP地址、 端口与所述后端服务器的 IP地址、 端口 关联, 并将所述关联关系更新到所述消息转发表中。  Establishing a TCP connection between the gateway and the backend server according to the handshake request message; associating an IP address and a port of the browser client with an IP address and a port of the backend server, and updating the association relationship to The message forwarding table.
3、 根据权利要求 1或 2所述的方法, 其特征在于, 所述方法还包括: 通过网关与后端服务器的 TCP连接接收所述后端服务器发送的请求响应 消息, 所述请求响应消息包括: 所述后端良务器的 IP地址和端口;  The method according to claim 1 or 2, wherein the method further comprises: receiving, by using a TCP connection between the gateway and the backend server, a request response message sent by the backend server, where the request response message includes : the IP address and port of the backend server;
根据所述后端服务器的 IP地址和端口查询所述消息转发表, 获得与所述 后端良务器的 IP地址和端口关联的浏览器客户端的 IP地址和端口; 根据所述浏览器客户端的 IP地址和端口, 通过网关与所述浏览器客户端 的 TCP连接将所述请求响应消息发送至与所述浏览器客户端的 IP地址和端口 对应的浏览器客户端。 Querying the message forwarding table according to the IP address and port of the backend server, and obtaining an IP address and a port of a browser client associated with the IP address and port of the backend server; And sending, according to the IP address and port of the browser client, the request response message to a browser client corresponding to the IP address and port of the browser client through a TCP connection between the gateway and the browser client.
4、 根据权利要求 2所述的方法, 其特征在于, 所述根据所述握手请求消 息建立网关与所述后端服务器的 TCP连接, 具体包括:  The method according to claim 2, wherein the establishing a TCP connection between the gateway and the backend server according to the handshake request message specifically includes:
析取所述握手请求消息包含的所述后端服务器的 IP地址和端口; 根据所述后端服务器的 IP地址和端口建立网关与所述后端服务器的 TCP 连接。  Extracting an IP address and a port of the backend server included in the handshake request message; establishing a TCP connection between the gateway and the backend server according to an IP address and a port of the backend server.
5、 一种网关, 其特征在于, 所述网关包括:  A gateway, wherein the gateway includes:
接收模块, 用于通过网关与浏览器客户端的传输控制协议 TCP连接接收 浏览器客户端发送的用户请求消息, 所述用户请求消息包括: 所述浏览器客户 端的 IP地址和端口;  The receiving module is configured to receive, by using a gateway, a transmission control protocol TCP connection of the browser client, a user request message sent by the browser client, where the user request message includes: an IP address and a port of the browser client;
第一获取模块, 用于根据所述浏览器客户端的 IP地址和端口查询消息转 发表, 获得与所述浏览器客户端的 IP地址和端口关联的后端服务器的 IP地址 和端口;  a first obtaining module, configured to obtain, according to the IP address of the browser client and the port query message, the IP address and port of the backend server associated with the IP address and port of the browser client;
发送模块, 用于根据所述后端服务器的 IP地址和端口, 通过网关与所述 后端服务器的 TCP连接将所述用户请求消息发送至与所述后端服务器的 IP地 址和端口对应的后端服务器。  a sending module, configured to send, by using a TCP connection between the gateway and the backend server, the user request message to the IP address and port corresponding to the backend server according to an IP address and a port of the backend server End server.
6、 如权利要求 5所述的网关, 其特征在于, 所述网关还包括:  The gateway according to claim 5, wherein the gateway further comprises:
握手消息接收模块, 用于通过网关与浏览器客户端的 TCP连接接收浏览 器客户端发送的握手请求消息, 所述握手请求消息包含后端服务器的 IP地址 和端口; 连接建立模块,用于根据所述握手请求消息建立网关与所述后端服务器的 TCP连接; The handshake message receiving module is configured to receive, by using a TCP connection between the gateway and the browser client, a handshake request message sent by the browser client, where the handshake request message includes an IP address and a port of the backend server; a connection establishing module, configured to establish, according to the handshake request message, a TCP connection between the gateway and the backend server;
更新模块, 用于将所述浏览器客户端的 IP地址、 端口与所述后端服务器 的 IP地址、 端口关联, 并将所述关联关系更新到所述消息转发表中。  And an update module, configured to associate an IP address and a port of the browser client with an IP address and a port of the backend server, and update the association relationship into the message forwarding table.
7、 如权利要求 5或 6所述的网关, 其特征在于, 所述网关还包括: 响应消息接收模块, 用于通过网关与后端服务器的 TCP连接接收所述后 端服务器发送的请求响应消息,所述请求响应消息包括:所述后端服务器的 IP 地址和端口;  The gateway according to claim 5 or 6, wherein the gateway further comprises: a response message receiving module, configured to receive a request response message sent by the backend server by using a TCP connection between the gateway and the backend server The request response message includes: an IP address and a port of the backend server;
第二获取模块, 用于根据所述后端服务器的 IP地址和端口查询所述消息 转发表, 获得与所述后端服务器的 IP地址和端口关联的浏览器客户端的 IP地 址和端口;  a second obtaining module, configured to query the message forwarding table according to an IP address and a port of the backend server, and obtain an IP address and a port of a browser client associated with an IP address and a port of the backend server;
响应消息发送模块, 用于根据所述浏览器客户端的 IP地址和端口, 通过 网关与所述浏览器客户端的 TCP连接将所述请求响应消息发送至与所述浏览 器客户端的 IP地址和端口对应的浏览器客户端。  a response message sending module, configured to send, by using a TCP connection between the gateway and the browser client, the request response message to an IP address and a port corresponding to the browser client according to an IP address and a port of the browser client Browser client.
8、 如权利要求 6所述的网关, 其特征在于, 所述连接建立模块具体包括: 解析单元, 用于析取所述握手请求消息包含的所述后端服务器的 IP地址 和端口;  The gateway according to claim 6, wherein the connection establishing module specifically includes: a parsing unit, configured to extract an IP address and a port of the backend server included in the handshake request message;
建立单元, 用于根据所述后端服务器的 IP地址和端口建立网关与所述后 端服务器的 TCP连接。  And a establishing unit, configured to establish a TCP connection between the gateway and the back end server according to the IP address and port of the backend server.
9、 一种通信系统, 其特征在于, 所述通信系统包括浏览器客户端、 网关 和后端服务器;  9. A communication system, characterized in that the communication system comprises a browser client, a gateway and a backend server;
所述浏览器客户端, 用于通过与所述网关的传输控制协议 TCP连接发送 用户请求消息, 所述用户请求消息包括: 所述浏览器客户端的 IP地址和端口; 所述网关, 用于通过与浏览器客户端的所述 TCP连接接收浏览器客户端 发送的所述用户请求消息; 根据所述用户请求消息中浏览器客户端的 IP地址 和端口查询消息转发表, 获得与所述浏览器客户端的 IP地址和端口关联的后 端服务器的 IP地址和端口; 根据所述后端服务器的 IP地址和端口, 通过与所 述后端服务器的 TCP连接将所述用户请求消息发送至与所述后端服务器的 IP 地址和端口对应的后端良务器; The browser client, configured to send by using a transmission control protocol TCP connection with the gateway a user request message, the user request message includes: an IP address and a port of the browser client, and the gateway is configured to receive, by using the TCP connection with a browser client, the user request message sent by a browser client Obtaining an IP address and a port of the backend server associated with the IP address and port of the browser client according to the IP address and port query message forwarding table of the browser client in the user request message; according to the backend server The IP address and port, the user request message is sent to a backend server corresponding to the IP address and port of the backend server through a TCP connection with the backend server;
所述后端服务器, 用于接收所述网关转发的用户请求消息。  The backend server is configured to receive a user request message forwarded by the gateway.
10、 根据权利要求 9所述的系统, 其特征在于,  10. The system of claim 9 wherein:
所述浏览器客户端还用于通过与所述网关的 TCP连接发送握手请求消息, 所述握手请求消息包含所述后端服务器的 IP地址和端口;  The browser client is further configured to send a handshake request message by using a TCP connection with the gateway, where the handshake request message includes an IP address and a port of the backend server;
所述网关还用于通过与所述浏览器客户端的 TCP连接接收所述浏览器客 户端发送的所述握手请求消息;根据所述握手请求消息建立与所述后端服务器 的所述 TCP连接; 将所述浏览器客户端的 IP地址、 端口与所述后端服务器的 IP地址、 端口关联, 并将所述关联关系更新到所述消息转发表中。  The gateway is further configured to receive, by using a TCP connection with the browser client, the handshake request message sent by the browser client, and establish, according to the handshake request message, the TCP connection with the backend server; Associating the IP address and port of the browser client with the IP address and port of the backend server, and updating the association relationship to the message forwarding table.
11、 根据权利要求 9或 10所述的系统, 其特征在于,  11. A system according to claim 9 or 10, characterized in that
所述后端服务器还用于通过与所述网关的 TCP连接向所述网关发送请求 响应消息, 所述请求响应消息包括: 所述后端良务器的 IP地址和端口;  The backend server is further configured to send a request response message to the gateway by using a TCP connection with the gateway, where the request response message includes: an IP address and a port of the backend server;
所述网关还用于通过与所述后端服务器的 TCP连接接收所述后端服务器 发送的请求响应消息; 根据所述请求响应消息中的后端服务器的 IP地址和端 口查询所述消息转发表, 获得与所述后端服务器的 IP地址和端口关联的浏览 器客户端的 IP地址和端口; 才艮据所述浏览器客户端的 IP地址和端口, 通过与 所述浏览器客户端的 TCP连接将所述请求响应消息发送至与所述浏览器客户 端的 IP地址和端口对应的浏览器客户端; The gateway is further configured to receive a request response message sent by the backend server by using a TCP connection with the backend server; query the message forwarding table according to an IP address and a port of the backend server in the request response message. Obtaining the IP address and port of the browser client associated with the IP address and port of the backend server; and according to the IP address and port of the browser client, The TCP connection of the browser client sends the request response message to a browser client corresponding to the IP address and port of the browser client;
所述浏览器客户端还用于: 接收所述网关发送的所述请求响应消息。  The browser client is further configured to: receive the request response message sent by the gateway.
PCT/CN2012/075776 2011-12-30 2012-05-19 Method, gateway and communication system for browser client directly communicating with back-end server WO2013097401A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201110456297.9 2011-12-30
CN201110456297.9A CN102546794B (en) 2011-12-30 2011-12-30 Method for directly communicating browser client with back-end server as well as gateway and communication system

Publications (1)

Publication Number Publication Date
WO2013097401A1 true WO2013097401A1 (en) 2013-07-04

Family

ID=46352740

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/075776 WO2013097401A1 (en) 2011-12-30 2012-05-19 Method, gateway and communication system for browser client directly communicating with back-end server

Country Status (2)

Country Link
CN (1) CN102546794B (en)
WO (1) WO2013097401A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113613348A (en) * 2021-08-11 2021-11-05 北京达佳互联信息技术有限公司 Connection establishing method and device, electronic equipment and storage medium
CN114386152A (en) * 2022-01-14 2022-04-22 中国电建集团昆明勘测设计研究院有限公司 Lightweight BIM model linkage labeling system based on WebSocket

Families Citing this family (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102932436A (en) * 2012-10-19 2013-02-13 广东中科遥感技术有限公司 Remote sensing conference and collaborative plotting system and method, browser and server
CN102984218B (en) * 2012-11-12 2016-08-24 北京奇虎科技有限公司 Browser and login method thereof and system
CN102932471B (en) * 2012-11-12 2015-11-18 北京奇虎科技有限公司 Browser logon server and realize browser log in method and system
CN102938788B (en) * 2012-11-15 2016-03-30 易程科技股份有限公司 The processing method of event and device
CN103023907B (en) * 2012-12-21 2017-12-01 北京奇虎科技有限公司 The method for obtaining site information, equipment and system
CN103118410B (en) * 2013-02-18 2015-10-07 广州市动景计算机科技有限公司 Method of mobile communication, system and the server for mobile communication
CN103546543A (en) * 2013-09-29 2014-01-29 北京京东尚科信息技术有限公司 Client device for electronic commerce and method and system for supplying information
CN104580106A (en) * 2013-10-24 2015-04-29 北大方正集团有限公司 Communication method and communication device
CN103546584B (en) * 2013-11-13 2018-08-14 努比亚技术有限公司 Information-pushing method and system
CN103634382B (en) * 2013-11-20 2019-10-18 科大讯飞股份有限公司 A kind of system and method for realizing real-time, interactive on webpage
CN103945003B (en) * 2014-05-06 2017-06-06 北京邮电大学 A kind of method that WebRTC clients connect dynamic adaptive selection
CN105488095A (en) * 2015-09-30 2016-04-13 小米科技有限责任公司 Search result access method, apparatus and system
CN105391536A (en) * 2015-10-28 2016-03-09 浪潮(北京)电子信息产业有限公司 Communication method and device between client end and service end
CN106201375B (en) * 2016-07-01 2019-02-19 浪潮通用软件有限公司 A method of the network share print control based on WebSocket
CN108124007A (en) * 2017-12-19 2018-06-05 深圳交控科技有限公司 The method and apparatus of message data real-time Transmission
CN110691033A (en) * 2019-09-02 2020-01-14 视联动力信息技术股份有限公司 Monitoring data processing method and device and storage medium
CN111314313A (en) * 2020-01-19 2020-06-19 成都康赛信息技术有限公司 Cloud pushing method based on message
CN111355784B (en) * 2020-02-20 2022-10-25 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for processing request information
CN112565214A (en) * 2020-11-26 2021-03-26 中国船舶工业系统工程研究院 Data transmission method, system and medium based on WebSocket
CN112859752B (en) * 2021-01-06 2021-12-28 华南师范大学 Remote monitoring management system of laser embroidery machine
CN112905928B (en) * 2021-05-07 2021-08-03 杭州米络星科技(集团)有限公司 Webpage refreshing method and device, electronic equipment and storage medium
CN114363427A (en) * 2021-12-24 2022-04-15 北京鼎普科技股份有限公司 Method for acquiring information of host equipment in real time based on browser
CN114553945A (en) * 2022-01-15 2022-05-27 江苏秉信科技有限公司 Message pushing method for power intranet cloud platform-crossing unified framework gateway
CN115242766A (en) * 2022-08-02 2022-10-25 亚数信息科技(上海)有限公司 Method for HTTPS transparent gateway based on two-layer network bridge

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101534302A (en) * 2009-04-16 2009-09-16 杭州华三通信技术有限公司 Method for providing TCP service, system and relevant device thereof
WO2010127327A1 (en) * 2009-05-01 2010-11-04 Kaazing Corporation Enterprise client-server system and methods of providing web application support through distributed emulation of websocket communications

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI310275B (en) * 2004-10-19 2009-05-21 Nec Corp Virtual private network gateway device and hosting system
CN100341301C (en) * 2005-05-25 2007-10-03 复旦大学 Gateway penetration method based on UDP flow media server of NAT
CN101184275A (en) * 2007-12-19 2008-05-21 Ut斯达康通讯有限公司 Service implementing method and system and mobile terminal of mobile terminal rolling screen amusement
CN101257450A (en) * 2008-03-28 2008-09-03 华为技术有限公司 Network safety protection method, gateway equipment, client terminal as well as network system
CN101350814A (en) * 2008-08-26 2009-01-21 成都卫士通信息产业股份有限公司 Safety remote access technology and gateway thereof
CN101741817B (en) * 2008-11-21 2013-02-13 中国移动通信集团安徽有限公司 System, device and method for multi-network integration
CN102025746B (en) * 2010-12-21 2013-04-17 北京星网锐捷网络技术有限公司 Method, device and network equipment for establishing transmission control protocol (TCP) connection

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101534302A (en) * 2009-04-16 2009-09-16 杭州华三通信技术有限公司 Method for providing TCP service, system and relevant device thereof
WO2010127327A1 (en) * 2009-05-01 2010-11-04 Kaazing Corporation Enterprise client-server system and methods of providing web application support through distributed emulation of websocket communications

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
I. HICKSON ET AL., THE WEBSOCKET PROTOCOL DRAFT-HIXIE-THEWEBSOCKETPROTOCOL-76., 6 May 2010 (2010-05-06), pages 4 - 6 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113613348A (en) * 2021-08-11 2021-11-05 北京达佳互联信息技术有限公司 Connection establishing method and device, electronic equipment and storage medium
CN113613348B (en) * 2021-08-11 2023-08-29 北京达佳互联信息技术有限公司 Connection establishment method, device, electronic equipment and storage medium
CN114386152A (en) * 2022-01-14 2022-04-22 中国电建集团昆明勘测设计研究院有限公司 Lightweight BIM model linkage labeling system based on WebSocket
CN114386152B (en) * 2022-01-14 2024-03-29 中国电建集团昆明勘测设计研究院有限公司 Light BIM model linkage labeling system based on WebSocket

Also Published As

Publication number Publication date
CN102546794A (en) 2012-07-04
CN102546794B (en) 2015-01-21

Similar Documents

Publication Publication Date Title
WO2013097401A1 (en) Method, gateway and communication system for browser client directly communicating with back-end server
WO2019205907A1 (en) Intelligent device communication platform based on mqtt message protocol
US10382543B2 (en) System and device for enabling any network functionality client or server in a HTML5 application
EP3259898B1 (en) Message bus service directory
US9503529B2 (en) System and method to transport HTTP over XMPP
WO2017045276A1 (en) Terminal interconnecting method, device, and storage medium
US9124494B2 (en) Method and apparatus of performing remote management of a managed machine
WO2012079321A1 (en) Method, system and apparatus for providing stream media service
WO2015021650A1 (en) Transmission method, device and system for media stream
CN106817341B (en) A kind of Session Initiation Protocol throttling Transmission system and method towards mobile Internet
US10574518B2 (en) Method and apparatus of performing remote management of a managed machine
WO2012000220A1 (en) Method for achieving automatically receiving group message on webpage
WO2019184262A1 (en) Multi-type media data network address translation traversing method, terminal and system
CN113162989A (en) MQTT-Websocket-based message transceiving method
CN108683653A (en) A kind of active message push system based on WebSocket
WO2015139390A1 (en) Multicast data processing method, apparatus, and system, sending device, and receiving client
WO2021008567A1 (en) Request transmission method and apparatus based on full duplex communication protocol
WO2017113816A1 (en) Method and device for peer-to-peer network connection
US8650313B2 (en) Endpoint discriminator in network transport protocol startup packets
WO2013120325A1 (en) Browser-to-browser direct communication method, device and communication system
US8443057B1 (en) System, method, and/or apparatus for establishing peer-to-peer communication
WO2013170812A1 (en) Transmission method for media data stream and thin client
Cui et al. Research and Implementation of WEBRTC Signaling via websocket-based for real-time multimedia communications
KR101746925B1 (en) The caching method and apparatus using peripheral device
WO2014101388A1 (en) Attachment transmission method, device, and system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 12863362

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 12863362

Country of ref document: EP

Kind code of ref document: A1