240 CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN if(tempReference.doLoop) (Best web hosting site)
240 CHAPTER 8 PERSISTENT COMMUNICATIONS PATTERN if(tempReference.doLoop) { window.setTimeout(”PrivateLoop(” + tempReference.index + “)”, tempReference.callDelay); } } tempReference.server2Client.username = tempReference.username; tempReference.server2Client.password = tempReference.password; tempReference.server2Client.get(tempReference.baseURL); } In the implementation of PrivateLoop, the parameter index is the index of the ClientCommunicator instance stored in the array property instances that represents an active reading stream. The variable tempReference is assigned the currently active instance of ClientCommunicator. Having a valid instance of ClientCommunicator, an HTTP call can be made. The next step is to assign the property openCallback with a function implementation that assigns the Accept HTTP header used to implement the Permutations pattern on the client side. Then the property complete is assigned a function implementation that is responsible for processing any messages sent by the server. Notice that only messages that have an HTTP status code 200 are processed, and the others are ignored. The assumption is that if there is a message that the server wants to send to the client, the body of the request will contain content, and hence an HTTP status code 200 is sent. This was done for simplicity purposes, but in your application you might want to process the error messages and other HTTP status codes. After the HTTP status code and potential message have been processed, and if the property doLoop is true, the method window.setTimeout is called again. The delay is not necessary but is speci fied by the property tempReference.callDelay. And finally, before making the asynchronous call, the function PrivateLoop assigns the username and password properties for a potential required authorization. The last action of PrivateLoop is to call the get method to retrieve any messages that need to be processed by the client. To end the polling of the reading stream, the previously illustrated ClientCommunicator. end method is implemented as follows: function ClientCommunicator_end() { this.doLoop = false; } The implementation to end polling the reading stream is simple, but the cessation of querying does not happen right away. If a query is still executing, it is completed, but a new query is not started. The last piece of functionality that needs to be implemented is the ClientCommunicator. send method that writes content to the writing stream and is implemented as follows: function ClientCommunicator_send(mimetype, contentLength, content) { var client2Server = new Asynchronous client2Server.username = this.username; client2Server.password = this.password; client2Server.complete = function(status, statusText,
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.