Explanation of web sockets and server-side Javascript (especially focused on node.js)

I want to create a chat room using HTML5 web sockets, but I'm pretty lost. From what I can say, the following is required:

  • Web Socket Support Browser (Chrome, Safari)
  • Some kind of server-side scripting
  • Some client side scripts

I have number 1 down :), but number 2 is seriously turning me off. Besides the amateur work of PHP (usually in the context of Drupal), I have virtually no server-side experience coding. I usually code a lot in Javascript, and read fantastic things about node.js. So I thought I'd try to use it to play with web sockets.

I installed node.js on a Mac Leopard computer (it installs in Home> node), but I really don't know where to go from there. The node.js website provides an example of "Hello World" that I tried (I put the code in the example.js file and saved it in the root directory of the "node"), but I will only get the following answer in the terminal:

The server is running on http://127.0.0.1:8124/

I would LOVE node.js and web sockets for mannequins. Thanks for any help that can be provided.

+3
source share
3 answers

, WebSocket node.js: http://github.com/LearnBoost/Socket.IO-node

, , http, , , .. ( node). , node.js .

: http://www.tutorialspoint.com/http/index.htm

websockets

+4

RingoJs http://ringojs.org, JavaScript . , , websocket.

  var websocket = require("ringo/webapp/websocket");

  exports.serverStarted = function(server) {
      var context = server.getDefaultContext();
      websocket.addWebSocket(context, "/websocket", function (socket) {
          // this function, being passed the socket, is called everytime
          // a new socket connection is made.

          // overwrite onMessage to intercept the messages         
          socket.onmessage = function(m) {
          };
      });
  };

  // send smth to the client
 fooSocket.send('your message')

socket.onmessage . , , .

:

+2

Source: https://habr.com/ru/post/1760921/


All Articles