A library to make working with websockets easier.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.js 692B

123456789101112131415161718192021222324252627282930313233343536
  1. var SockSugar = require("..");
  2. var server = new SockSugar({
  3. port: 8081
  4. });
  5. server.on("connection", function(sock) {
  6. console.log("connection!");
  7. sock.on("request", function(req) {
  8. console.log("Request for "+req.url);
  9. console.log(req.data);
  10. req.reply({
  11. msg:" Hello there!"
  12. });
  13. });
  14. });
  15. process.stdin.on("data", function(data) {
  16. str = data.toString("utf8");
  17. if (str.split(/\s+/)[0] == "send") {
  18. console.log("Sending myEvent to all connections.");
  19. server.socks.forEach(function(sock) {
  20. sock.send("myEvent", {
  21. msg: str.replace(/^\w+\s+/, "").trim()
  22. });
  23. });
  24. } else {
  25. console.log("Unknown command.");
  26. }
  27. });
  28. console.log("Running SockSugar on port 8081.");