Socket – onError, onClose are not getting triggered

  • Deniz
    Participant
      4 months, 1 week ago #62591

      I have this function which handles connections to multiple barcode scanners. I noticed that the onError and onClose events are not getting triggered, even when disconnecting the scanners.

      Where can I find the socket class to inspect it? In Simplifier’s ‘Code’ section I can only find the js files for websocket, but not for socket.

      I am relatively sure that these events still worked under Simplifier 8. Was there a change here in Simplifier 9?

       

      function fxConnectSocket(sUrl, sVarName, fxOnData = () => {}) {
      let socket = new Socket();
      const aParts = sUrl.split(‘:’);
      const iId = Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
      const handleConnection = (status) => {
      sap.ui.getCore().getModel(‘variableHolder’).setProperty(/${sVarName}, status);
      };
      const reconnect = () => {
      console.log(Socket ${iId} of type ${sVarName} connection to ${sUrl} closed. Reconnecting in 1 second...);
      setTimeout(() => socket = fxConnectSocket(sUrl, sVarName, fxOnData), 1000);
      };
      socket.open(aParts[0], parseInt(aParts[1]), () => {
      handleConnection(‘Connected’);
      console.log(Socket ${iId} of type ${sVarName} connection to ${sUrl} opened.);
      }, (event) => {
      handleConnection(‘Disconnected’);
      console.log(Socket ${iId} of type ${sVarName} connection to ${sUrl} failed with code ${JSON.stringify(event)}.);
      // reconnect();
      });

      socket.onData = fxOnData;

      socket.onError = function(event) {
      handleConnection(‘Disconnected’);
      console.error(Socket ${iId} of type ${sVarName} had an error:, JSON.stringify(event))

      reconnect();
      };
      socket.onClose = function(event) {
      handleConnection(‘Disconnected’);
      console.log(Socket ${iId} of type ${sVarName} connection to ${sUrl} closed because of error ${JSON.stringify(event)}.);
      reconnect();
      };

      return socket;
      }

      • This topic was modified 4 months, 1 week ago by Deniz.
      Lukas Henninger
      Moderator
        Has successfully completed the online course Introduction
        Has successfully completed the online course Intermediate (200)
        Has successfully completed the online course Advanced (300)
        Has successfully completed the online course Basics (100)
        Has successfully completed the online course Advanced (310)
        Has successfully completed the online course Advanced (320)
      4 months ago #62617
      Up
      1
      Down
      ::

      Hi Deniz,

       

      You can find the code for the sockets in our GitHub repository. This plugin is included in the mobile Client.

      I don’t think there was a change in the Sockets code in recent times, so it should not be related to the update.

      I hope this helps you out in identifying your issue.

       

      Lukas

      Deniz
      Participant
        4 months ago #62636
        Up
        0
        Down
        ::

        Thank you!

      Viewing 3 posts - 1 through 3 (of 3 total)

      You must be logged in to reply to this topic.