Hi,
I have been using the examples from the github repository:
Websocket-api NODE JS
The issue is that the socket connection does not open, but times out by default. I am using one with authentication and for the sake of simplicity, I have extracted temporary token from POSTMAN, and including that token directly in the new WS object. My code looks like below:
var WebSocket = require('ws')
var ip = require("ip");
var position = ip.address();
var testToken = // manually extracted token from POSTMAN
var appID = // app ID
var WS_URL = 'wss://streaming.trkd.thomsonreuters.com:15000/WebSocket';
console.log("Connecting to WebSocket " + WS_URL + " ...")
_websocket = new WebSocket(WS_URL, "tr_json2", {
'headers':{'Cookie':"AuthToken=" + testToken + ";AuthPosition=" + position + ";applicationId=" + appID +";"}});
_websocket.onopen = onOpen;
_websocket.onclose = onClose;
_websocket.onerror = onError;
function onOpen(evt){
console.log("WebSocket successfully connected!");
}
function onClose(evt){
console.log("WebSocket Closed");
}
function onError(evt){
console.log("Error");
console.log(evt)
}
This is basicly a copy paste from the github repository node JS example, only with hardcoded values. If I run the code, it does not trigger any functions below, only the error one roughly 30 seconds after attempting to connect. My error message in TERMINAL :
$ node custom.js
Connecting to WebSocket wss://streaming.trkd.thomsonreuters.com:15000/WebSocket ...
Error
ErrorEvent {
target:
WebSocket {
_events: { open: [Function], close: [Function], error: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
readyState: 2,
protocol: '',
_binaryType: 'nodebuffer',
_closeFrameReceived: false,
_closeFrameSent: false,
_closeMessage: '',
_closeTimer: null,
_closeCode: 1006,
_extensions: {},
_isServer: false,
_receiver: null,
_sender: null,
_socket: null,
url: 'wss://streaming.trkd.thomsonreuters.com:15000/WebSocket',
_req: null },
type: 'error',
message: 'connect ETIMEDOUT 159.220.24.157:15000',
error:
{ Error: connect ETIMEDOUT 159.220.24.157:15000
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14)
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '159.220.24.157',
port: 15000 } }
WebSocket Closed
My code, as I believe, is basicly a copy paste from the github functions in the official repo. Cant think anything where it breaks, or why am I getting refused. I generate a fresh token with POSTMAN, before sending it.
Regards,
Koppany