amazon web services - Why does grails websockets connection fail but continue to receive messages that have been subscribed to in the browser while using an AWS ELB? -


using grails 2.5.5 spring-websockets plugin 1.3.1 , tomcat 8.0.37.

while using aws elastic load balancer, following error shown in javascript console when loading application in browser

websocket connection 'ws://...s.com/application/stomp/059/uyqk9cdn/websocket' failed: error during websocket handshake: unexpected response code: 400

from research has been found elb doesn't support websockets , proxying within elb, third party load balancer or potentially using new application load balancer (the applications not in vpc not easy solution) might required.

however, after error, following logging received:

web socket opened...  >>> connect accept-version:1.1,1.0 heart-beat:10000,10000 <<< connected version:1.1 heart-beat:0,0 user-name:admin  connected server undefined  >>> subscribe id:sub-0 destination:/topic/sometopic 

messages received client fine when broadcast

<<< message destination:/topic/sometopic content-type:application/json;charset=utf-8 subscription:sub-0 message-id:xb71g__u-16 content-length:89 

the code initiate websocket connection

<r:require module="spring-websocket"/>     <r:script>         var socket = new sockjs("${createlink(uri: '/stomp')}");         var client = stomp.over(socket);          client.connect({}, function () {             var topic = "/topic/digticketupdated";             console.log("subscribing -> " + topic);             client.subscribe(topic, function (message) {                 console.log("push message received server");                 updatestatus(message.body);             });         });     </r:script> 

this taken grails-spring-websocket github page.

is possible figure out if fallback has kicked in, websocket working or other scenario. summarise :

  1. is websocket falling protocol?
  2. is there way rid of 400 error?

thanks suggestions in comments, found after "unexpected response code: 400" thrown, sockjs attempted use long post xhr request emulate web socket , worked. viewable in network tab of chrome developer tools "xhr_streaming".

to prevent 400 error showing in development console, configurable switch implemented web socket connections not attempted when known not supported, such on aws elb. achieved passing removing "websocket" allowed protocols when instantiating sockjs :

var allowedprotocols = ['xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling'] var socket = new sockjs(uri, {}, {protocols_whitelist : allowedprotocols}); var client = stomp.over(socket); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -