How Maxmsp send message through socket.io

Alfred Chen's icon

Hi everyone here.
I'm a newbie learning MaxMSP and trying to do some interactive things.
But I'm facing a problem though I've tried to search on the internet.
Here's the problem. I want to send a message or signal from Maxmsp to p5.js sketch.
But I've added socket client to my sketch.js. It's still not working. I'm not sure what the problem is.
The goal is to send the message (int value) and make the sketch.js could draw a circle with the radius of the message.

Server.js

Maxmsp patch

Sketch.js

Léo Huet's icon

Hi Alfred,
Only seeing your message today. I think you solve your issue or maybe you just moved on but here is a reply :
You have to replace your "socket.on ('message', (msg) ..." by a Max.addHandler function in your script.js. This function will be triggered by a message you send from Max to the script, like your "message $1". Then, you just io.emit the message like you did and retrieve it in your sketch.js.
Here is in attachment a server.js and sketch.js files that do exactly what you want. You didn't mention it but I guess you have an index.html with your sketch.js linked in it.

server.js
application/x-javascript 0.92 KB
server.js file

sketch.js
application/x-javascript 0.37 KB
P5JS sketch