I hope this is not too much to ask.
Im new to this NodeJS tech, which I think is amazing, but Im not a really good programmer, I found this awesome example http://softwareas.com/video-sync-with-websocket-and-node/, but I cant make it work. I believe the code its outdated, and Im running the latest Node, I've been trying to fix it but I cant get near close. I dont fully understand how websockets work, and is giving me a headache.
When I run the server it runs just fine.
var sys = require("util");
var ws = require('websocket-server');
var userCount = [];
var server = ws.createServer({
debug: true
});
server.addListener("connection", function(conn){
server.broadcast("userCount " + ++userCount);
conn.addListener("message", function(message){
server.broadcast(message);
});
});
server.addListener("close", function(conn){
server.broadcast("userCount " + --userCount);
});
server.listen(8000, "localhost");
function log(msg) {
sys.puts(+new Date + ' - ' + msg.toString());
};
But when I interact with the client (Log as a user) the server crashes and I get this error in the console, and I've no idea what it means. http://i.stack.imgur.com/cLlga.png I'm really new to this, and I don't understand D:, any help is really appreciated
That package 'websocket-server' is unmaintained for 4 years, you should consider using another one.
There have been several forks in github, https://github.com/miksago/node-websocket-server/network, but with few changes more, so they are almost same obsolete.
Trying the examples in the package, https://github.com/miksago/node-websocket-server/tree/master/test/manual, the echo-server.js (very similar to your code) doesn't work, server hangs (or appears to hang), with no traces. If you try chat-server.js it does work, but I don't know if it does what you need/want.
You can run those examples with command:
node test/manual/chat-server.js
Double check if there is a newer module that does the same :)