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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
3 0 0 1

Not getting response when message is sent successfully

It has been some time now working on integration of Refinitiv WebSocket's API and our core banking system, so far I am able to connect to the WebSocket without issues, I can as well send messages successfully, the challenge I am having is that, after I sent the message, I want to be able to log the response as we get response when testing with postman, I am not able to get that response, I find this weird because if we have an error on our request payload(Message) I am able to get that response logged and the error message of why the request does not go through. Can you maybe help me out on this? Below is the code snipet;



const connectWebSocket = async () => {
  const protocol = process.env.RDP_WEBSOCKET_PROTOCOL;
  const server = process.env.RDP_WEBSOCKET_SERVER;
  const port = process.env.RDP_WEBSOCKET_PORT;
  const securityProtocol = process.env.RDP_SEC_PROTOCOL;
  try {
    const RDP_WEB_SOCKET_URL = `${protocol}://${server}:${port}/WebSocket`;
    const wsUrl = RDP_WEB_SOCKET_URL;
    const service = process.env.REALTIME_SERVICE;


    const message = {
      ID: 4,
      Streaming: false,
      Key: {
        Service: service,
        Name: "LSL=",
      },
    };
    const ws = new WebSocket(wsUrl, securityProtocol);
    ws.on("open", () => {
      console.log("WebSocket connection established.");
      // Send your message as JSON
      ws.send(JSON.stringify(message), () => {
        console.log("Message sent to WebSocket server:", JSON.stringify(message));
      });
    });
    ws.on("message", (data) => {
      const message = data.toString();
      try {
        const parsedMessage = JSON.parse(message);
        console.log("Received message from server:", parsedMessage);
      } catch (error) {
        console.error("Error parsing message:", error);
      }
    });
    ws.on("close", (code, reason) => {
      console.log(
        `WebSocket connection closed with code ${code}. Reason: ${reason}`
      );
    });
    ws.on("error", (error) => {
      console.error("WebSocket error:", error);
    });
  } catch (error) {
    console.error(
      "Error occurred while establishing WebSocket connection:",
      error
    );
  }
};
#technologywebsocketsresponsenode-jstypescript
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.

Upvotes
Accepted
24.6k 54 17 14

Hello @folokolereko

Thank you for reaching out to us. I have checked your code. I cannot find any code that sends Login message to the WebSocket server.

### Your Code ###

  1. Establish a WebSocket connection to ADS server.
  2. Establish a WebSocket connection success (OnOpen callback triggered).
  3. Send a snapshot request to the ADS.

Basically, the Real-Time WebSocket connection workflow is as follows:

  1. Establish a WebSocket connection to ADS server.
  2. Establish a WebSocket connection success (OnOpen callback triggered).
  3. Send a JSON Login request to the ADS.
  4. The ADS server sends a Refresh response message for the Login request back to the application.
  5. Once the application receive a Login Refresh response message, the application can start sending item request messages to ADS.

step-1.png

step-2.png

You can find more detail about the WebSocket API workflow from the WebSocket API tutorial page. page.


step-1.png (66.7 KiB)
step-2.png (93.8 KiB)
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.

Thank you, you really saved my day!
Upvotes
24.6k 54 17 14

Hi @folokolereko

Additionally, there is the WebSocket API - deployed RTDS examples available on the GitHub repository.

Even though it uses JavaScript and different coding style, but you could apply the message flow logic to your application.

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.

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.