Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using socket.io without client embedded in html

Every where I m searching, socket.io is used in two part: one client and one server.

The server is a node.js application, but everytime, the client is a html page embedding the client code.

Is there a way to do so without html? For example, to make multiple node.js application communicating.

EDIT:

The use case is, I have a "program" in node.js, which I would like to send logs on demand to a server application. I m struggling in implementing the client code in the app.

Ultimately, if the server can send short message to all or one app, it would be wonderful because it would allow me to direct every app from a web page hosted by the server.

._____. ._____. ._____.
| app | | app | | app |
|_____| |_____| |_____|
   |       |       |
   |_______|_______|
           |
           | Logs
           V
       .________. Command   ._____.
       | server |---------->| app |
       |________|           |_____|
like image 887
DrakaSAN Avatar asked Nov 01 '22 07:11

DrakaSAN


1 Answers

You can use socket.io-client module to communicate with socket.io server.

https://github.com/LearnBoost/socket.io-client

Example client code -

var io = require('socket.io-client'),
socket = io.connect('localhost', {
    port: 1337
});

socket.on('connect', function () { 
  console.log("socket connected"); 
});

socket.emit('news', { hello: 'world' });
like image 166
vinayr Avatar answered Nov 08 '22 04:11

vinayr