244 CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN interface (Ftp web hosting)
244 CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN interface is to read the requested URL, test it for validity, and reorganize the MIME types to their appropriate priorities. The real work lies in the IRouter interface instance router. It is responsible for sending content that the IRewriter instance wants to send. In the implementation of the modified IRouter interface, the missing application logic would be embedded. In the Permutations pattern, the IRewriter interface instance was illustrated to rewrite a URL to the most appropriate content. Rewriting the URL usually means sending a new link to the client to download. And in the examples illustrated by the Permutations pattern, that meant having a servlet rewrite the URL so that an ASP.NET or JSP page can process the actual request. In the case of the Persistent Communications pattern, a rewrite is necessary only for the sake of the client because whatever the URL is rewritten to, the servlet will still process the request. Therefore, it is more fitting that the servlet process the request without sending the redirect to the client. Be careful, though, because the redirection that is being discussed is the redirection outlined in the Permutations pattern that matches the resource to the most desired request. If the redirection were to reference another resource, the redirection would have to be sent to the client, as will be illustrated in the Example: Server Push section. To manage this additional work, the IRouter interface has two additional methods used to process the HTTP POST (ProcessPost) or GET (ProcessGet). Calling the ServerCommunicator Intelligently Both the client-side and server-side implementation are complete. When the Send Data button is clicked and then the Start Communications button is clicked, a round-trip of content will occur. There is a problem in the implementation of ClientCommunicator and GlobalStatus. The problem is that the reading stream will ask whether there is any data available, and the server will respond with a yes and send it. What the reading stream is not asking is whether there is any new data available and to send only the new data. As the implementation stands, there is no piece of information sent in the reading that indicates what content has already been sent. The solution requires changing the way that the resource is called, and specifically adding a custom HTTP header. Remember in the definition of GlobalStatus, there was the data member _callCount. The data member was not added for triviality, but has a specific purpose and is a version number for the latest state. Whenever an HTTP POST is executed, the call counter is incremented, meaning that the state has been updated. Using the call counter as a reference, a server can indicate whether new content is available. The server cannot know when to send a message to the client without getting a helping hand from the client, because the server does not know which state the client has already received. The client needs to implement a change, whereby the client notes the version number and stores the value somewhere on the client temporarily. Then when the next request is made, the value is sent to the server and that value helps the server decide whether the client should wait for new data or be immediately sent the latest data. The sending and retrieving of the value could be implemented as an HTTP cookie. Using an HTTP cookie is simple because the client has to do nothing other than accept the HTTP cookie. Then every time the client makes a call, the cookie is sent automatically and the server can read which version the client has downloaded. However, for this example, a custom HTTP header will be written because some people are wary of HTTP cookies. The cookie example will be illustrated in the Example: Presence Detection section. On the client side, ClientCommunicator is modified as follows (with the changes in bold):
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.