Или так:
node:
var ipaddress = '127.0.0.1';
var port = 9000;
function testWebSocketServerAndNotification()
{
var WebSocketServer = require('ws').Server;
var path = require('path');
var notifier = require('node-notifier');
var message = 'Hello from Node.js';
var path2Image = 'e:\\MyWork\\NodeWorkBench\\TestApp\\image\\infoBalloon.png';
var wss = new WebSocketServer({host:ipaddress, port:port});
wss.broadcast = function(data)
{
for (var i in this.clients)
{
this.clients[i].send(data);
}
};
wss.on('connection', function(ws)
{
ws.on('message', function(message)
{
wss.broadcast(message);
notifier.notify
({
title: 'My notification',
message: `Message: '${message}'`,
sound: true,
time: 5000,
wait: true,
icon: path.join(__dirname, 'image', 'notificationIcon.png'),
contentImage: path2Image,
});
});
});
console.log('Слушаем адрес ' + ipaddress + ' на порте: ' + port + ' ...');
}
php:
<?php
require_once "e:\\MyWork\\web\\Script\\PHP\\PHP_SocketIO_Client\\socket.io.php";
$socketio = new SocketIO();
echo iconv("UTF-8", "CP866", "exit для выхода\n");
while(true)
{
$input = fgets(STDIN);
if(trim($input) == "exit")
{
break;
}
if ($socketio->send("127.0.0.1", 9000, iconv("CP866", "UTF-8", trim($input))))
{
echo iconv("UTF-8", "CP866", "Сообщение отправлено. Можете продолжать:\n");
} else
{
echo iconv("UTF-8", "CP866", "Какой-то сбой :(\n");
}
}
exit("Jobe done");
?>
socket.io.php брал отсюда
https://github.com/psinetron/PHP_SocketIO_Client