I have spent too many days on this now and been unable to get a solution.
I have a node server running perfectly (very basic) but working and have web pages that can connect and work with the server.
But what I now need to do is from an debian based Raspberry pi run a JS file using Node which can connect to my existing node server.
Is this possible or is my understanding of node incorrect.
This is my basic server
var socket = require('socket.io');
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
var io = socket.listen(server);
io.on('connection', function (client) {
console.log('Connected');
client.on('deviceevent', function (data) {
io.sockets.emit('return',{ param1: data.param1, param2: data.param2, param3: data.param3 });
console.log(data);
});
client.on('disconnect', function () {
io.sockets.emit('user disconnected');
});
});
server.listen(3000);
console.log('Listening');
And this is how I was expecting to be able to connect via a cmd line JS file.
(This doesnt work at all)
var socket = require('socket.io');
mysocket = socket.connect('http://192.168.1.70:3000');
mysocket.emit('deviceevent', { param1: "update", param2: "0", param3: "1" });
So is it even possible? I have the server working but damned if I can get a js file that I can run at cmd line to connect.
Any help would be greatly appreceiated.
BTW. socket.io examples are all related to a web page connecting to the server which I am already doing.