I was wondering a little bit about the websocket dat as I’ve definitely got a connection working with my node server using socket.io and I can broadcast from the server to clients but I’m not getting any data into touchdesigner besides the odd empty message. Does anybody have a working example and does the data need to be in a specific format?
I’ve tried a few different methods of sending with no success, the server log shows they’re sending though.
We are still developing the WebSocket DAT, so it’s only been tested with a few cases so far. If you have a case/server you can share with us this will help us iron out all the issues.
function handler (req, res) {
fs.readFile(__dirname + ‘/index.html’,
function (err, data) {
if (err) {
res.writeHead(500);
return res.end(‘Error loading index.html’);
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on(‘connection’, function (socket) {
io.sockets.emit(‘this’, { will: ‘be received by everyone’});
});[/code]
I get a message through on index.html connecting but it’s empty, the server log recieves the full message however. this is the first time I’ve used websockets so I might be getting it a bit wrong. I’ve used send, emit, broadcast…pretty much every way of sending a message in that last little section.
Heres index.html:
<script src="js/socket.io.min.js"></script>
<script>
var socket = io.connect('http://localhost:80');
$(document).ready(function() {
socket.broadcast.emit('sent from client');
io.sockets.emit('message', { message: "sockets emit from client" });
});
</script>
I have not digged yet personally into such setup but one can find on github an example of how to use node.js and sockets.io to send OSC messages to Touch or other OSC clients: github.com/automata/osc-web
Yeah I’ve got an OSC setup currently but it’s slow and only sends messages due to using PHP as the handler on a WAMP server, it works by jquery sending to my php script which includes the PHPtoOSC class and then that fires across to touch, I wasn’t aware that it was possible to send and recieve osc via websockets without PHP so thanks for that link, receiving data from touch probably makes it the best solution for now.
Just goes to show how people saying somethings impossible on stackoverflow really can cause more harm than good. It’s all still just a big hack though…websocket DAT to the rescue I’m sure
Well, I’ve tried but with no luck. Here is what I get:
It seems that the first message is correctly sent by node server, but is not received by Touch. And then, on the browser side, it doesn’t seem to be able to send a message back (as per the javascript error into chrome console).
Edit: I tried with different ports too (it’s why there is a 8000 port on the second image), but I don’t really know what is going wrong with the error.
Ok I’ve found another problem with the Websocket DAT. Basically if you start the server after creating the websocket DAT then it won’t connect as the websocket DAT is seen as a client and until the client refreshes its connection it won’t register messages, deleting and recreating the websocket DAT will fix this. A connect to server pulse parameter or something could help fix this for situations where touch is starting up the node server via system commands.
Heres the example code I tested with which works perfectly well if the websocket DAT is created after the server has started running. The websocket DAT needs to be on port 8000 and must have socket.io formatting turned on.
This sends to all clients except the one sending (in our case index.html)
io.sockets.emit('get_message', data);
This sends back to the client which sent the message, and in this example appends the message in a list so you can see what text messages you have sent.
-One point is that the websocket DAT only receives messages when touch power is on. It would be nice if it could receive messages while touch power is off, like controllers CHOPs (mouse, joystick, etc), and OSCin CHOP, reducing the need of processing power, so one could possibly activate touch power on via a websocket message.
-As websocket is bidirectional, is it possible to send messages from touch to node server or to the browser, with the websocket DAT, and how ? I don’t see clearly how it can be done actually.
Thanks for clarifying the structure of the project.
I see that the final websocket DAT could allow us to define one’s UI in HTML/CSS/JS while communicating back and forth with Touch Designer for doing all the stuff it is good at.
Hi guys, have any of you been having odd timeout issues? I’ve got a situation where after a while when sending from a webpage to touch using socket.io format it just stops working. I can see it registering on the server so I assume the server is passing that on but touch wont pick it up. If I uncheck socket.io then check it back on again it will re-connect and fix the issue. Anybody got any tips for stopping timeouts or will I have to just send a redundant message as a heartbeat?