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

Best Answer

  • Gurpreet
    Answer ✓

    @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.

Answers

  • @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.

  • @lzhuang1
    Is there any error from your python script? and Is this possible to share your test app?
    I usually use an IP Address 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. And then compare a result with your script.

  • 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!

  • @Gurpreet.

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