views:

192

answers:

3

This is specifically about GWT's RequestBuilder, but should apply to general XHR as well. My company is having me build a near realtime chat application over HTTP. Yes, I do realize there are better ways to do chat aplications, but this is what they want. Eventually we want it working on the iPad/iPhone as well so flash is out, which rules out websockets and comet as well, I think?

Anyway, I'm running into issues were I've set GWT's RequestBuilder timeout to 10 seconds and we get very random and sporadic timeouts. We've got error handling and emailing on the server side and never get any errors, which suggests the underlying XHR request that RequestBuilder is built on, never gets to the server and times out after 10 seconds.

We're using these request to poll the server for new messages rather often and also for sending new messages to the server and also polling (less frequently) for other parts of application. What I'm afraid of is that we're running into the browsers limit on concurrent connections to the same domain (2 for IE by default?).

Now my question is - If I construct a RequestBuilder and call it's send() method and the browser blocks it from sending until one of the 2 connections per domain is free, does the timeout still start while the request is being blocked or will it not start until the browser actually releases the underlying XHR?

I hope that's clear, if not please let me know and I'll try to explain more.

A: 

Seems like half the time, you answer your own question as soon as you post it.

Via: http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/http/client/package-summary.html

Pending Request Limit - Modern web browsers are limited to having only two HTTP requests outstanding at any one time. If your server experiences an error that prevents it from sending a response, it can tie up your outstanding requests. If you are concerned about this, you can always set timeouts for the request via RequestBuilder.setTimeoutMillis(int).

WesleyJohnson
+1  A: 

Browsers allowed only 2 connections per hostname; that has now changed. 'Modern' browsers allow upto 6 simultaneous connections - it varies between browsers. See http://www.browserscope.org/ - network tab.

As regards the timer, it starts before GWT invokes xhr.send(), so your suspicion is right. See Request.java and RequestBuilder.java if you want to trace it out.

sri
I chose this one as the answer since is answered what I was asking specifically and added additional info on how trace out the functionality and see how it work across different browsers as well. Thanks!
WesleyJohnson
+2  A: 

On the GWT Incubator doc page is an article explaining server push. With said technique you only hold one connection open all the time.

Gipsy King
And there's a question about it on SO too ;) http://stackoverflow.com/questions/2391203/what-does-it-call-in-gwt-to-make-2-ui-consistent
Igor Klimer
+1 for offering some alternate solutions, however we'ved talked about doing push or long polling and the boss doesn't want to go down that route yet. I suspect me way do so, though, if we can't increase the performance and stability of what we're doing now.
WesleyJohnson