3

I'm trying to find out what the difference is between websocket.mtgox.com and socketio.mtgox.com for the MtGox streaming API. Looking at the Connecting section it looks like there are several combinations to be used:

websocket.mtgox.com/mtgox
socketio.mtgox.com/mtgox

both with http or https.

As far as I can see, there is no mention that they are different, however, I know from trying out things myself that they do behave differently. I've also seen in forums that other people have similar questions/problems as I have related to this.

Does anyone know what the differences are? Also are these differences expected and documented somewhere?

Further, the code snippet uses https as the protocol. Excuse my ignorance, but shouldn't we use ws or wss instead of http and https? Can someone explain that difference?

Thanks in advance for any information related to my questions!

UPDATE: Actually, it looks like the URI scheme for websockets should be ws: or wss: and not like in the example http: or https:. Maybe this is a typo in the example or what's the deal for MtGox?

UPDATE: So testing things in the browser, {ws,wss,http,https}://socketio.mtgox.com/mtgox all work and I don't see any difference. On the other hand, {ws,wss,http,https}://websocket.mtgox.com/mtgox all result in HTTP 400 Bad Request. Looking in the browser console I got the following error:

XMLHttpRequest cannot load http://websocket.mtgox.com/socket.io/1/?t=1367857246057. Origin null is not allowed by Access-Control-Allow-Origin.

Any ideas what might be going on?

  • Let me know if this question should have been posted somewhere else like on stackoverflow.com. Thanks! – murrekatt May 6 '13 at 12:27
3

Origin null is now allowed.

Your Origin header is not being set.

Try running your code in the browser from an actual domain name other than something like about:blank.

In chrome running:

var ws = new WebSocket('ws://websocket.mtgox.com/mtgox');
ws.onmessage = function(e){ console.log(e); };

results in failure from about:blank. However from an actual domain name results in success.

  • Thanks! Yes, that is the case. However, this header is not necessary unless you're a browser according to the standard. MtGox however, enforces this for all. – murrekatt Jun 8 '13 at 8:46
  • This solved my problem! Thank you so much. I have been stuck for hours! – samol Nov 12 '13 at 5:33
1

OK, so after playing around with this for a while in the browser I have found out a few things that probably were somewhat obvious. :)

So even if there is no mention that websocket.mtgox.com is different from socketio.mtgox.com it really is, and the difference is that the former is a real WebSocket endpoint while the latter is a Socket.IO endpoint. Of course not very surprising looking at the names ;) Now for a beginner like me that wasn't completely obvious as I assumed Socket.IO could speak WebSocket and thus the endpoints were the same. Hence, this question. This was no the case here.

The Socket.IO endpoint accepts all URI schemes {http, https, ws, wss} while the real WebSocket endpoint only accepts the expected {ws, wss}.

At the moment I have all combinations working.

http://socketio.mtgox.com/mtgox
https://socketio.mtgox.com/mtgox
ws://socketio.mtgox.com/mtgox
wss://socketio.mtgox.com/mtgox

ws://websocket.mtgox.com/mtgox
wss://websocket.mtgox.com/mtgox

It's unclear it the http and https URI schemes are at all meaningful or if they just happen to work. Probably just that.

In short, there are two hosts: one for Socket.IO and one for WebSocket and both work with or without TLS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.