node JS WSS connection timeout
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
Best Answer
-
Hello @k1001
Firstly, The WS URL for TRKD should be wss://streaming.trkd.thomsonreuters.com/WebSocket/ (without port 15000), not wss://streaming.trkd.thomsonreuters.com:15000/WebSocket/ .
Secondly, the Elektron WebSocket API supports the authentication via a JSON Login request message only. You cannot set TRKD authentication token via HTTP Header like TRKD JSON REST API. You need to set your username, application id and TRKD authentication token in the JSON login request message as following structure:
{
"Domain":"Login",
"ID":1,
"Key":{
"Elements":{
"ApplicationId":"your TRKD application id",
"AuthenticationToken":"Your TKRD Token",
"Position":"<your position>"
},
"NameType":"AuthnToken",
"Name":"Your TKRD username"
}
}I have modified the market_price.js example and tested with my TRKD account. The application works fine.result.zip
I connect to TRKD WebSocket server with this code:
var WS_URL_TRKD = 'wss://streaming.trkd.thomsonreuters.com/WebSocket/';
_websocket = new WebSocket(WS_URL_TRKD, "tr_json2");Then I set my Login request message with the following code:
function onOpen(evt) {
console.log("WebSocket successfully connected!");
var msg = '{"ID":1,"Domain":"Login","Key":{"Name":"","NameType":"AuthnToken","Elements":{"ApplicationId":"","Position":"","AuthenticationToken":""}}}';
var msgJson = JSON.parse(msg);
msgJson.Key.Name = user
msgJson.Key.Elements.ApplicationId = appId
msgJson.Key.Elements.Position = position
msgJson.Key.Elements.AuthenticationToken = testToken
_websocket.send(JSON.stringify(msgJson));
console.log("SENT:");
console.log(JSON.stringify(msgJson, null, 2));
}0
Answers
-
Seems to be the case of missing ping messages. Can you verify that your app receives ping message from server and responds with a pong message.
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛