For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
10 5 3 5

WebSocket can only connect server with machine name but not with actual IP address

Hi, I have a python script which connects to TREP server through websocket api for getting real-time quotes. It works when I use the host name but not for IP address - the script need to run in an environment which is not aware of the machine name - any suggestions, thanks

elektronrefinitiv-realtimeelektron-sdkwebsockets
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @lzhuang1,

Thank you for your participation in the forum.

Is the reply below satisfactory in answering your question? If yes please click the 'Accept' text next to the most appropriate reply.

If you have already known an answer, please share your answer, and then accept it. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Upvotes
Accepted
22k 58 14 21

@lzhuang1, In addition to trying the "provided API samples", can you try to check if the IP address is listening on the websocket port: 15000.

Try:

>>telnet ip.ip.ip.ip 15000

Where ip is the IP address of ADS providing websocket connection.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@Gurpreet.

I use an IP of another machine actually. Sorry for the confusion. Thanks!

Upvotes
7.6k 15 6 9

@lzhuang1
Is there any error from your python script? and Is this possible to share your test app?
I usually use an IP Address to test the WebSocket on my ADS and not found any issue.

Can you also try WebSocketsAPI_TryitNow_Doc example from https://developers.refinitiv.com/elektron/websocket-api/downloads connecting to the server using the same IP Address and port?
You may also try a python example from WebSocket API Sample Applications to test the server. Then you can compare the result with your python script.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

There is no errors when I use machine name to connect, The code is paste below:

ws_address = "ws://{}:{}/WebSocket".format("hostname", 15000)

print("Connecting to WebSocket " + ws_address + " ...")

web_socket_app = websocket.WebSocketApp(ws_address, header=['User-Agent: Python'], on_message=on_message, on_error=on_error, on_close=on_close, subprotocols=['tr_json2'])

web_socket_app.on_open = on_open

wst = threading.Thread(target=web_socket_app.run_forever)

wst.start()

When I change "hostname" to the actual IP of the same host, it complains on:

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Please advise, thanks!

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.