The Websocket DAT

socket.broadcast.emit('send_message',{message: 'hello world'});

the above sends to touch from the server fine. I’ve tested it. I’m currently building up a bigger example.

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.

index.html:

<html>
<head>

<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/socket.io.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var socket = io.connect('http://localhost:8000');

    $('#sender').click(function() {
            var user_message = $('#message_box').val()
            socket.emit('send_message',{message: user_message});
    });

    socket.on('get_message', function(data) {
        $('#data').append(data.message);
        });
    });
</script>
</head>
<body>
<div id='data'></div>
<input type='text' id='message_box' placeholder='send message'>
<button id='sender'>Send Message</button>
</body>
</html>

server.js:

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(8000);

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) {
    socket.on('send_message', function(data) {
    data.message = data.message + '<br/>';
    socket.broadcast.emit('get_message',data);
    io.sockets.emit('get_message', data);
    });
}); 

The two methods of sending are:

socket.broadcast.emit('get_message',data);

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.

Thanks Ennui for the code.

I got some trouble with the script pathes in the header, but I finally got it working with different ones.

Is your js folder at the root of your app like this ? And is socket.io.min.js an actual library or a pointer to a node_module path ?


node-modules
js
js\jquery.min.js
js\socket.io.min.js
server.js
index.html
package.json

As per some other remarks to Derivative team:

-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 this promising operator by the way.

Yeah I’ve attached a zip of the full structure. Yeah my headers rubbish as I just pasted without context… :unamused:

Yes a sending data example/feature implementation? would be lovely.
socketout.zip (3.69 MB)

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.

Just a quick heads up, we’ve actively been testing / fixing / expanding these features so we’ll have some updates to share soon.
Thanks,
Rob

Hi again.
The latest posted build includes a redesigned WebSocket DAT, that allows for full two-way script control.

For a brief description see:
derivative.ca/wiki088/index. … Socket_DAT

In particular, check out the section on scripting:
derivative.ca/wiki088/index. … Socket_DAT

Cheers,
Rob.

What version of Socket.IO does this DAT support/require?

Socket.IO is up to 0.9. I’'ve been using libraries that still use 0.6 (django-socketio).

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?

Can I ask what stacks people are using with the Websocket DAT? Having no luck setting this up with this one Flask-SocketIO/gevent-socketio.

Malcolm, can you please confirm what versions of Socket.IO are supported?

I’m using 0.9.11 with express and it’s solid as a rock, if you want I can send an example setup your way.

I’m experiencing no issues so far, other than having to start my network, AFTER starting my NodeJs-SocketIO server.

Node v0.10.22

Haven’t tested long term however, and would appreciate if anyone has experienced any timeout issues and what their solution was.

But the same caveat is for connected USB devices as well. Connect them FIRST before launching your network.

The solution is to send a heartbeat back within the timeout period.

I use a beat hooked up to a chop execute dat that has the following:

def offToOn(channel, sampleIndex, val, prev): op('websocket1').sendText("2::") return

See the socket.io specification for more details on that stuff.

[url]https://github.com/LearnBoost/socket.io-spec[/url]

It’s worth also adding that using 1:: rather than 2:: will force a connection which is useful at startup.

Hi Ennui, a sample setup would be great.

All, I’ve created a public spreadsheet for DAT use cases listing what’s been put in this thread and known issues / status

docs.google.com/a/modprods.com/ … FUk8E/edit

Maybe I’ve missed something obvious but I can’t see sufficient documentation to get this working.

Is the Websocket DAT only listening for a particular event or namespace?

Attached is my example.

Node: 0.10.28 (64 bit)
Nodemon: 1.2.0
Socket.io: 0.9.11 (both client and server included in the attached zip)
TouchDesigner 088: 21300 (64 bit)

The client upon loading index.html sends an event called my_event which in turn has an argument called hello with the value world. This is sent to localhost on port 8080.

The server, upon recieving my event then takes its hello arguments value and uses it to broadcast a hello event, thus sending the event hello to touchdesigner with the value world.

The beat CHOP in the touchdesigner section triggers a heartbeat message back to the server so touchdesigner doesn’t lose it’s connection. There is no toggling of active on startup though so to make your initial connection you’ll need to make sure you toggle it off then on again.
socket-example.zip (8.56 MB)

Thanks Ennui, got your v0.9 Socket.IO combo working this end but not with v1. So no way to do binary streaming it seems.

Derivative, I’ve updated the spreadsheet below with Ennui’s base use case info. I’m guessing namespace support and v1 Socket.IO support are the issues I’m hitting. It’s a bit hard comparing apples to oranges without a reference implementation that has logging but I’ve added some new tabs with debug info for the broken use cases I’m interested in (socket.io v1 and Flask-SocketIO using socket.io v0.9)

docs.google.com/a/modprods.com/ … =855701498

Top of my wishlist:
Compatibility with latest SocketIO example
socket.io/get-started/chat/
Operator Snippet showing how to use sendbinary and receiveBinary - e.g. save incoming byte array into a movieinTop

Now I think about it I don’t think I’ve seen anything in the changelog regarding socket.io 1 and there are some pretty big syntax changes with it so I imagine it’s just a websocket DAT update thats needed.

I found this new tutorial about flask and websockets.
It’s very simple and also explains some very simple client code. I think is good for begginers on webscokets like me!! :blush:

Hi !
To be clear im a real noob about server client socket.io websocket etc …

i see Richard sucess to communicate true local website with touchdesigner
and i see some video on youtube sucess comunicate on local

i recently buy my own server
and i want know if there are lots of change to make
with the Socket-exemple.zip project

to make it works on webhosting between my server and random public use my website with a mobile phone for exemple ^^

im hope im clear()
for now i think i just need to look all the file and change line localhost:8080 to my own server

but cause im a noob maybe im totally wrong !
maybe the websockets and flask solutions is better i really don’t know ^^ i just need to be a little driven on this ^^

thx !