I have a simple node.js server using socket.io that's listening for messages. I'm sending messages to the server from a Perl script - The server seems to be receiving the messages, but not recognizing the "channel" of the message. How do I correctly construct node.js/socket.io messages to be sent from a Perl script?
Here's my node.js server:
var express = require('express');
var app = express.createServer();
var io = require('socket.io').listen(app);
app.listen(3000);
io.sockets.on('connection', function (socket) {
console.log("In connection");
socket.on('testevent', function (data) {
console.log("In testevent");
console.log(data);
});
});
Here's part of my Perl script which sends the message:
#$clientID is set to 1598760311220985572 earlier... obtained from a handshake
$uri = "http://192.168.3.13:3000/socket.io/1/xhr-polling/$clientID";
$message = "5:::{'name':'testevent','args':['hello!']}";
$request = HTTP::Request->new( 'POST', $uri );
$request->content( $message );
print $response = $browser->request( $request )->as_string;
Server log after message received from Perl script:
info - handshake authorized 1598760311220985572
debug - client authorized for
In connection
debug - xhr-polling received data packet 5:::{'name':'testevent','args':['hello!']}
So, the node.js server seems to be receiving the message, but not recognizing the channel "testevent", because I would expect the server to log the string "In testevent" if it interpreted the message correctly.
Am I formatting my message correctly in Perl, or maybe my server code is wrong?