I'm trying to connect to it in my C++ app.
If I send a handshake to
http://socketio.mtgox.com:80/mtgox, it doesn't answer
http://websocket.mtgox.com:80/mtgox, it sends 400 Bad request
I Googled this one:
http://socketio.mtgox.com:80/socket.io/1/websocket, this one connects, switches to websocket protocol, then sends me two messages saying "1::" and "2::".
What do I do on my side?
I tried to send {"channel":"24e67e0d-1cad-4cc0-9e7a-f8523ef460fe","op":"subscribe"} - nothing happens...
What's the right URL to connect and what do I send to subscribe to a channel?
Alternatively, can anyone please post a simple .js code that successfully connects to MtGox from a HTML page?
Without node.js or socket.io, just a built in HTML5 Websocket class.
I have this script:
<script language="javascript" type="text/javascript">
var output;
function init()
{
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket()
{
var websocket = new WebSocket('wss://socketio.mtgox.com:443/mtgox');
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
function onOpen(evt)
{
writeToScreen("CONNECTED");
//doSend("WebSocket rocks");
}
function onClose(evt)
{
writeToScreen("DISCONNECTED");
}
function onMessage(evt)
{
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
}
function onError(evt)
{
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message)
{
writeToScreen("SENT: " + message);
websocket.send(message);
}
function writeToScreen(message)
{
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
window.addEventListener("load", init, false);
</script>
but it only prints ERROR: undefined and disconnects.
Thank you!