Many internet applications are implemented using client-server communication via the well-known transmission control protocol over internet protocol (TCP/IP) or user datagram protocol over internet protocol (UDP/IP). However, with the deployment of client-side firewalls, communication between a server and the client may be restricted. A firewall may allow client-server communication using the well-known hypertext transfer protocol (HTTP or HTTPS) for communication, while blocking non-HTTP/HTTPS client-server communication. For example, the firewall may allow normal HTTP communication between the client and server, but may prevent the client from establishing a long-lived persistent TCP connection to the server.
HTTP uses a request-response communication model. Therefore, HTTP does not serve well when a server needs to “push” data to a client, i.e., when a server needs to send unsolicited data to a client. However, with many applications, such as instant messenger (IM), the server needs to be able to send unsolicited data, e.g., a notification event, to the client.
Existing solutions for enabling the server to send unsolicited data to the client require the client to poll the server periodically in order to check if there is any data that needs to be sent to the client. Upon receiving a poll, e.g., request, from the client, the server is able to send a response to the client. It should be appreciated that in the HTTP request-response model, the server immediately replies to the client request, even if there is no data available to be sent to the client. Consequently, when there is no data available to be sent to the client, the polling by the client and the corresponding empty response by the server amounts to wasted communication and associated overhead.
Therefore, the client polling approach using the HTTP request-response model has two significant shortcomings. First, the polling by the client in the absence of data at the server consumes processor cycles on both the client and the server without a corresponding productive communication of data. Second, when data becomes available at the server for transmission to the client, the server will have to wait for the next polling by the client to deliver the data to the client. Therefore, depending on the polling frequency, the data may not be delivered to the client in a timely manner.
In one embodiment, a method is disclosed for communicating between a client and a server. The method includes an operation for opening a transmission control protocol (TCP) connection between the client and the server. A hypertext transfer protocol (HTTP) client request is then transmitted from the client to the server over the open TCP connection. Upon receipt of the HTTP client request at the server, a determination is made as to whether client data is pending at the server. Upon determining that client data is pending at the server, a server response including the client data is transmitted from the server to the client over the open TCP connection. Then, promptly upon receiving the server response at the client, the client transmits a new HTTP client request to the server. Upon determining that client data is not pending at the server, the server waits for client data to become available before sending a server response to the client, thereby maintaining the open TCP connection.
In another embodiment, a system for controlling communication between a client and a server is disclosed. The system includes a client communication module and a server communication module. The client communication module is defined to open a TCP connection with the server communication module, and transmit a HTTP client request to the server communication module over the open TCP connection. The server communication module is defined to wait for client data to become available at the server communication module before sending a server response to the client communication module, thereby maintaining the open TCP connection.
In another embodiment, a computer readable medium having program instructions stored thereon for controlling server side communication with a client is disclosed. On the computer readable medium, program instructions are included for opening a TCP connection with a client. Program instructions are also included for receiving a HTTP client request from the client over the open TCP connection. Further program instructions are included for delaying a server response to the HTTP client request until client data becomes available for transmission to the client so as to maintain the open TCP connection. Program instructions are also included for transmitting a server response to the client over the open TCP connection when client data is pending for transmission to the client. Additionally, program instructions are included for receiving a subsequent HTTP client request from the client promptly upon the client's receipt of the server response so as to maintain an open TCP connection with the client.
In another embodiment, a method is disclosed for communicating between a client and a server. The method includes an operation for opening a TCP connection between a client and a server. An operation is then performed to transmit a HTTP client request from the client to the server over the open TCP connection. If client data is not pending at the server upon receipt of the HTTP client request at the server, the server is operated to wait for client data to become available before sending a server response to the client, thereby maintaining the open TCP connection. However, if client data is pending at the server upon receipt of the HTTP client request at the server, the server is operated to transmit a server response including the client data from the server to the client over the open TCP connection. The server response is tagged with a server response sequence number. Promptly upon receiving the server response at the client, the client is operated to transmit a new HTTP client request from the client to the server. The new HTTP client request includes the server response sequence number tagged to the server response most recently received by the client. Then, upon receiving the new HTTP client request at the server, the server is operated to verify that the server response sequence number included with the new HTTP client request matches the server response sequence number tagged to the most recently transmitted server response. If the server response sequence number included with the new HTTP client request does not match the server response sequence number tagged to the most recently transmitted server response, the server is operated to retransmit the most recently transmitted server response to the client.
Other aspects and advantages of the invention will become more apparent from the following detailed description, taken in conjunction with the accompanying drawings, illustrating by way of example the present invention.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced without some or all of these specific details. In other instances, well known process operations have not been described in detail in order not to unnecessarily obscure the present invention.
The client and server communication modules 103/107 are further defined to enable communication between the client 101 and the server 105 using a hypertext transfer protocol (HTTP) 111 over the TCP connection 109. As HTTP is a request-response protocol, the HTTP 111 communication between the client 101 and server 105 includes transmission of a client request 113 to the server 105, with a corresponding transmission of a server response 115 to the client 101. It should be understood that the server response 115 is the mechanism by which the server 105 is capable of communicating with the client 101. Therefore, the server 105 needs to receive a client request 113 in order to communicate data to the client 101 via the server response 115.
With regard to the method of
From the operation 201, the method proceeds with an operation 203 for transmitting a HTTP client request 113 from the client 101 to the server 105 over the open TCP connection 109. The transmitted HTTP client request 113 is defined to direct the server 105 to send any pending client data to the client 101. Upon receipt of the HTTP client request 113 at the server 105, a decision operation 205 is performed to determine if client data is pending at the server 105 for transmission to the client 101. If client data is pending at the server 105 upon receipt of the HTTP client request 113, an operation 207 is performed to transmit a server response 115 including the client data from the server 105 to the client 101 over the open TCP connection 109. Then, promptly and automatically upon receiving the server response 115 at the client 101, an operation 209 is performed to transmit a new HTTP client request 113 from the client 101 to the server 105. From operation 209, the method reverts back to the decision operation 205 for determining if client data is pending at the server 105.
In one embodiment, upon receiving the server response 115 at the client 101, the client 101 is operated to maintain the open TCP connection 109 and use the open TCP connection 109 to transmit the new HTTP client request 113 from the client 101 to the server 105. In another embodiment, upon receiving the server response 115 at the client 101, the client 101 is operated to close the open TCP connection 109, open a new TCP connection 109 between the client 101 and the server 105, and use the newly opened TCP connection 109 to transmit the new HTTP client request 113 from the client 101 to the server 105.
Referring back to operation 205, if client data is not pending at the server 105 upon receipt of the HTTP client request 113 at the server 105, an operation 211 is performed in which the server 105 is operated to wait for client data to become available before sending a server response 115 to the client 101, thereby maintaining the open TCP connection 109. It should be appreciated that operation 211 differs from the conventional HTTP request-response communication method which requires that server 105 immediately transmit a server response to the client 101 upon receipt of each client request regardless of whether or not client data is pending at the server 105.
While the server 105 is waiting for client data to become available, thereby holding open the TCP connection 109, it is possible that the TCP connection 109 will experience a timeout or network error condition. For example, the network error condition may be caused by a number of different occurrences, such as a router reboot or a connection reset, among others. Therefore, from the operation 211, the method includes a decision operation 213 to determine if a timeout or network error condition exists for the open TCP connection 109. If a timeout or network error condition does not exist, the method reverts back to the decision operation 205 for determining if client data is pending at the server 105. Thus, if a timeout or network error condition has not occurred, the server 105 continues to wait for client data to become available before sending the server response 115 to the client 101 over the open TCP connection 109. If a timeout or network error condition does exist at operation 213, the method proceeds with an operation 215 in which the client 101 is operated to retransmit the most recently transmitted HTTP client request 113 to the server 105. From operation 215, the method reverts back to the decision operation 205 for determining if client data is pending at the server 105. The method of
The method of
Referring back to the decision operation 205 in the method of
Promptly and automatically upon receiving the server response 115 at the client 101, an operation 219 is performed to transmit a new HTTP client request 113 from the client 101 to the server 105. Also, in operation 219, the client 101 is operated to include with each new HTTP client request 113 the server response sequence number tagged to the server response 115 most recently received by the client 101.
Upon receiving the new HTTP client request 113 at the server 105, the server 105 is operated to verify that the server response sequence number included with the new HTTP client request 113 matches the server response sequence number tagged to the most recently transmitted server response 115. Therefore, from the operation 219, the method proceeds with a decision operation 221 for verifying that the server response sequence number received in the new HTTP client request 113 is the correct server response sequence number. If the server response sequence number received in the new HTTP client request 113 is correct, the method reverts back to operation 205 for determining if client data is pending at the server 105.
If the server response sequence number received in the new HTTP client request 113 does not match the server response sequence number tagged to the most recently transmitted server response 115, the method proceeds with an operation 223 in which the server 105 is operated to retransmit the most recently transmitted server response 115 to the client 101. From operation 223, the method reverts back to operation 219 for transmitting a new HTTP client request 113 from the client 101 to the server 105, along with the server response sequence number tagged to the server response 115 most recently received by the client 101. The method of
It should be appreciated that the server response sequence number generation and verification, as implemented in operations 217, 219, 221, and 223 of the method of
The communication methods of
It should be appreciated that the communication methods of
The server 105 is defined to concurrently manage many open connections. Specifically, the server 105 is defined with a capability to simultaneously wait on events from multiple connections using event application programming interfaces (APIs), such as select( ), poll( ), and kevent( ). Additionally, the server 105 can optionally support HTTP keep-alive, such that the server 105 keeps the TCP connection 109 open after sending the server response 115 to the client 101. Support of the HTTP keep-alive feature by the server 105 further improves communication performance, as the client 101 needs to promptly and automatically transmit a new HTTP client request 113 to the server 105 upon receipt of the server response 115.
The communication methods of
With the above embodiments in mind, it should be understood that the invention may employ various computer-implemented operations involving data stored in computer systems. These operations are those requiring physical manipulation of physical quantities. Usually, though not necessarily, these quantities take the form of electrical or magnetic signals capable of being stored, transferred, combined, compared, and otherwise manipulated. Further, the manipulations performed are often referred to in terms, such as producing, identifying, determining, or comparing.
The invention can also be embodied as computer readable code on a computer readable medium. The computer readable medium is any data storage device that can store data which can be thereafter read by a computer system. The computer readable medium may also includes an electromagnetic carrier wave in which the computer code is embodied. Examples of the computer readable medium include hard drives, network attached storage (NAS), read-only memory, random-access memory, CD-ROMs, CD-Rs, CD-RWs, magnetic tapes, and other optical and non-optical data storage devices. The computer readable medium can also be distributed over a network coupled computer system so that the computer readable code is stored and executed in a distributed fashion.
Any of the operations described herein that form part of the invention are useful machine operations. The invention also relates to a device or an apparatus for performing these operations. The apparatus may be specially constructed for the required purposes, or it may be a general purpose computer selectively activated or configured by a computer program stored in the computer. In particular, various general purpose machines may be used with computer programs written in accordance with the teachings herein, or it may be more convenient to construct a more specialized apparatus to perform the required operations.
The above described invention may be practiced with other computer system configurations including hand-held devices, microprocessor systems, microprocessor-based or programmable consumer electronics, minicomputers, mainframe computers and the like. Although the foregoing invention has been described in some detail for purposes of clarity of understanding, it will be apparent that certain changes and modifications may be practiced within the scope of the appended claims. Accordingly, the present embodiments are to be considered as illustrative and not restrictive, and the invention is not to be limited to the details given herein, but may be modified within the scope and equivalents of the appended claims. In the claims, elements and/or steps do not imply any particular order of operation, unless explicitly stated in the claims.