Serving HTTP and websockets from the same domain?

211 views
Skip to first unread message

Josh Kamau

unread,
Mar 12, 2014, 7:54:38 AM3/12/14
to ve...@googlegroups.com
Hi ;

Today i have been doing some studying on sockjs.  From the documentation, it appears that its not advisable to server my 'ajax' requests and sockjs requests from the same domain.

From the sockjs github page:
"Although the 'SockJS' object tries to emulate the 'WebSocket' behaviour, it's impossible to support all features. One of the important SockJS limitations is the fact that you're not allowed to open more than one SockJS connection to a single domain at a time. This limitation is caused by a in-browser limit of outgoing connections - usually browsers don't allow opening more than two outgoing connections to a single domain. Single SockJS session requires those two connections - one for downloading data, other for sending messages. Opening second SockJS session at the same time would most probably block and can result in both sessions timing out."

Now in vert.x, i normally initialize my sockjs/http server as follows:

var httpServer = vertx.createHttpServer();

var sockJSServer = vertx.createSockJSServer(httpServer);

sockJSServer.bridge({prefix : '/eventbus'}, [], [] );

server.listen(8080);


If i access the eventbus and http from the same browser application, 
does it mean that will be using sockjs and http from the same domain.

Assuming that my browser does not support websockets, does 
it mean 'xhr_streaming'(or whatever sockjs fallsback to)  and 
my ajax requests will be competing for the 2 outgoing connections
that the browser provides?


I hope the question makes sense.

Thanks
Josh

Tim Fox

unread,
Mar 12, 2014, 8:45:30 AM3/12/14
to ve...@googlegroups.com
I'm not sure of the answer to that. I suggest posting on the sockjs google group.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh Kamau

unread,
Mar 12, 2014, 8:54:14 AM3/12/14
to ve...@googlegroups.com
Thanks Tim for the response.

It seems like its a bad idea to 'heavily' use the eventbus and ajax on the same domain if the browser does not support  websockets. (Am assuming websockets do not utilize the 2 available out going browser connection per domain.)


Josh

Tim Fox

unread,
Mar 12, 2014, 8:56:26 AM3/12/14
to ve...@googlegroups.com
I think it's a good idea to create no more than one SockJS (or vertxbus.js) connection from your client side JS.

tbh I can't see why you would want to create more than one connection anyway...

Josh Kamau

unread,
Mar 12, 2014, 9:03:27 AM3/12/14
to ve...@googlegroups.com
I meant. .. 1 sockjs connection ... and still do http ajax  .  


"This limitation is caused by a in-browser limit of outgoing connections - usually browsers don't allow opening more than two outgoing connections to a single domain. Single SockJS session requires those two connections - one for downloading data, other for sending messages" from sockjs github page.

Therefore, if i have 1 sockjs connection,  The single sockjs connection requires 'the to outgoing channels provided by the brower'  ... So if sockjs uses those ... what will my $.ajax(...) requests use?


Tim Fox

unread,
Mar 12, 2014, 9:20:36 AM3/12/14
to ve...@googlegroups.com
On 12/03/14 13:03, Josh Kamau wrote:
I meant. .. 1 sockjs connection ... and still do http ajax  .  


"This limitation is caused by a in-browser limit of outgoing connections - usually browsers don't allow opening more than two outgoing connections to a single domain. Single SockJS session requires those two connections - one for downloading data, other for sending messages" from sockjs github page.

Therefore, if i have 1 sockjs connection,  The single sockjs connection requires 'the to outgoing channels provided by the brower'  ... So if sockjs uses those ... what will my $.ajax(...) requests use?


Not sure ;) Maybe try it out and see what happens?
Reply all
Reply to author
Forward
0 new messages