A library to make working with websockets easier.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

server.js 692B

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
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.");