Answer the question
In order to leave comments, you need to log in
How to organize communication between php and node.js on a socket?
php
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$msg = "Пинг !";
$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 8080);
socket_close($sock);
var io = require('socket.io').listen(8080);
io.set('log level', 1);
io.set('heartbeats', true);
io.set('heartbeat timeout', 30);
io.set('heartbeat interval defaults',5);
io.set('heartbeat interval defaults',5);
io.sockets.on('connection', function (socket)
{
socket.on('message', function (msg)
{
console.log(msg);
});
});
Answer the question
In order to leave comments, you need to log in
I'm not a node expert, but most likely your TCP port is listening, but sent to the UDP port.
You need to open a UDP socket on the node, instead of socket.io
UDP nodejs
var dgram = require("dgram");
var server = dgram.createSocket("udp4");
server.on("error", function (err) {
console.log("server error:\n" + err.stack);
server.close();
});
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " +
rinfo.address + ":" + rinfo.port);
});
server.on("listening", function () {
var address = server.address();
console.log("server listening " +
address.address + ":" + address.port);
});
server.bind(8080);
// server listening 0.0.0.0:8080
And what were the reasons in php to use udp? it is more logical to use tcp.
Slick slider is good for this purpose. Slider Syncing section, just swap the navigation in the HTML so it's on top.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question