WebSocket & SocketIO auto-disconnects


#1

Hello, While trying to use the StreamTip WebSocket when I connect the WS receives the connection but then nearly instantaneously disconnects without any errors; I am doing this with NodeJS and am dumbfounded of how its working. I tested the same library against the websocket echo server and it works fine.


// Connection [StreamTip][WebSocket Singularity]
var WebSocket = require(‘ws’);
var sTip = new WebSocket(‘wss://streamtip.com/ws?access_token=’ + encodeURIComponent("“myAccessToken”));

sTip.on(‘open’, function open() {
console.log("[STip] WebSocketSecure Opened!");

sTip.on('message', function(data, flags) {
	console.log(data);
});

});

sTip.on(‘close’, function close() {
console.log(’[STip] Connection Lost?’);
});


#2

I have tries ws:// and wss://


#3

The close event contains an error message. You should read what it says to determine why you’re being disconnected.


#4

All it gave me was access defined; I retried with socket.io (I would prefer this over websocket) and now I receive the same error. but differently.

[Web] Server Online! Listening on Port:65
{ Error: xhr poll error
    at XHR.Transport.onError (C:\Users\Samuel\Desktop\WebTimer+\node_modules\eng
ine.io-client\lib\transport.js:64:13)
    at Request.<anonymous> (C:\Users\Samuel\Desktop\WebTimer+\node_modules\engin
e.io-client\lib\transports\polling-xhr.js:129:10)
    at Request.Emitter.emit (C:\Users\Samuel\Desktop\WebTimer+\node_modules\engi
ne.io-client\node_modules\component-emitter\index.js:133:20)
    at Request.onError (C:\Users\Samuel\Desktop\WebTimer+\node_modules\engine.io
-client\lib\transports\polling-xhr.js:307:8)
    at Timeout._onTimeout (C:\Users\Samuel\Desktop\WebTimer+\node_modules\engine
.io-client\lib\transports\polling-xhr.js:254:18)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5) type: 'TransportError', description
: 400 }
401::Access Denied::
var Socket = require('socket.io-client');
global.streamTip = Socket.connect('https://streamtip.com', {
    query: 'access_token='+Config.streamTipAccessToken
});

streamTip.on('error', function(err) {
	console.log(err);
});

#5

Then the access token you are using is invalid. If you are using the personal access token, you also need to pass client ID as described in the Authentication section of the documentation.


#6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.