octoblu / meshblu

Meshblu is a cross-protocol IoT machine-to-machine messaging system.
https://meshblu.readme.io/
MIT License
816 stars 181 forks source link

Issues Connecting via Socket.io #90

Closed RickCarlino closed 9 years ago

RickCarlino commented 9 years ago

Using the public MeshBlu server:

socket = io.connect 'wss://meshblu.octoblu.com', port: 443 # pardon my Cofeescript

Produces the following error:

WebSocket connection to 'wss://meshblu.octoblu.com/socket.io/?
EIO=3&transport=websocket&sid=VQHaAAao0qIZRUP7AASR' 
failed: Error during WebSocket handshake: Unexpected response code: 502

I provisioned my own server on localhost, which causes a stalled connection (no errors though) and a warning from chrome: CAUTION: Request is not finished yet!. Server logs do not show much information beyond that.

Does anyone have any ideas about this? Has the socket API changed recently?

Thanks.

iamruinous commented 9 years ago

Hmm nothing that I know of has changed. If you use the meshblu npm module do you get the same problems?

RickCarlino commented 9 years ago

We're actually using a Ruby based backend (via MeshRuby). What's strange is that MeshRuby appears to be connecting to the server just fine on the device side of things.

# Console log for our Ruby based device:
connect 
identify {"socketid"=>"789"}
ready {"api"=>"connect", "status"=>201, "socketid"=>"789", "uuid"=>"123", "token"=>"456"}

The web frontend (part that's giving the errors) is running Socket.io 1.3.3

I will try doing a version up/down grade to see if that changes anything. Do you think 1.3.3 could be the issue?

iamruinous commented 9 years ago

I love ruby!

If it helps, there's a browserified version of the npm library

  <script src="//cdn.octoblu.com/js/latest/meshblu.bundle.js"></script>

You can see it in use on developer console.

RickCarlino commented 9 years ago

Ok, now I'm getting somewhere. Looks like that link causes the same problem as with socket.io:

WebSocket connection to 'wss://meshblu.octoblu.com/socket.io/?EIO=3&transport=websocket&sid=rwoLX133iEGufS_XAATO' failed: Error during WebSocket handshake: Unexpected response code: 502

I will dive a little deeper tomorrow and let you know what I find. Thanks for the help.

RickCarlino commented 9 years ago

Ok, so here's what I've gotten so far:

Client (on Linux) Results message
Socket.io / Chrome 43 :broken_heart: WebSocket connection to 'wss://meshblu.octoblu.com/socket.io/?EIO=3&transport=websocket&sid=ggrF_xBNKgB2XDcqAAWf' failed: Error during WebSocket handshake: Unexpected response code: 502
MeshBlu.js / Chrome 43 :yellow_heart: Same Unexpected response code: 502 but still returns ready event (?)
Socket.io / Firefox 37 :yellow_heart: The connection to wss://meshblu.octoblu.com/socket.io/?EIO=3&transport=websocket&sid=8Tq2M2riSLKt7KYtAAfm was interrupted while the page was loading. socket.io.js:5258:0 and Firefox can't establish a connection to the server at wss://meshblu.octoblu.com/socket.io/?EIO=3&transport=websocket&sid=wjZquv30UyRO8oLQAAWj. socket.io.js:5258:0
MeshBlu.js / Firefox 37 :yellow_heart: same as Socket.io
MeshRuby (serverside socket.io client) :green_heart: Connects without issues.

UPDATE: After leaving the FF window open for some time, I saw CORS header errors. Is it possible that CORS is misconfigured on the serverside? This might explain why my server app is having no issues connecting- it does not bother with Flash / JSONP / XHR transports and goes straight to a websocket connection. Can't confirm though. I will take a deeper look today.

iamruinous commented 9 years ago

@RickCarlino we are doing source IP mapping on the load balancer, do you have multiple outbound IPs?

We can do a GoToMeeting or you can join us in https://gitter.im/octoblu/help for a more real-time chat. I'd like to help you get this resolved today if possible.

RickCarlino commented 9 years ago

@iamruinous I think that's what the issue might have been. Here's how I fixed it:

  1. Provisioned a new MeshBlu instance of my own and pointed my applications to that one
  2. Pull down the latest version (today)
  3. Everything works on my MeshBlu instance now, but:
    1. I am still getting 502's on the public instance.
    2. Can't use WSS://

Not sure what changed, or why I was able to get the instance running today and not 2 days ago, but I imagine it was either fixed in a recent PR, or when I tried this a few days ago there was an unseen misconfiguration on my part. Eitherway, this is enough to get me working again. Feel free to call me up or PM me on Twitter if you need help tracking down that 502 error.

iamruinous commented 9 years ago

@RickCarlino I just ran into @elbow-jason at Gangplank and we were chatting about these problems. We just released a pure websocket implementation yesterday to avoid all the socket.io problems people are having with non-javascript clients.

http://meshblu-websocket.readme.io/v2.0/docs/getting-started

It isn't the full API just yet but we're adding more to it every day. This could be a lot easier for you to implement.