NodeJs string transferring via web socket

    Javascriptbeginner

    LLRL
    Sep 22 2023 | 9:35 am
    Hello, I want to use WebSockets to send messages to a web page, today I used Node.js for the first time in Max. I referred to this example: https://github.com/Cycling74/n4m-examples/blob/master/sockets/max_sockets.js
    which allows me to send three values to the web page. However, I'm not sure how to modify the program to send three strings instead of three numbers. I have been trying for a whole day, but whenever I send a 3-string group message from Max, the web page always displays "NaN" (Not a number).
    I am trying to modify this part : Max.addHandler("send", (...args) => { console.log("send args: " + args); if (args.length === 3) { sender(args[0], args[1], args[2]); }
    But still I couldn't find out the right way...
    Can you please tell me how to modify the program to achieve this?
    Thank you!

    • Florian Demmer's icon
      Florian Demmer
      Sep 22 2023 | 10:20 am
      Hi there,
      just on first look it seems like the parsing of the values happens on the frontend. So the code to adjust wouldn't necessarily be the Node part but the JS that runs in the browser.
      It seems like in mySockets.js you can find the handle that processes incoming messages on the websocket.
      Share
    • LLRL's icon
      LLRL's icon
      LLRL
      Sep 23 2023 | 4:15 am
      Thank you so much Florian,
      After removing the math operations in mySockets.js, it works very well ! I now only have one issue left to solve, which is that I can't access port 8080 from external sources to see the webpage. I can see the webpage, but I can't see the continuously updating string values. Still working on a solution for that.
      Again thanks a lot !