我应该如何格式化socket.io消息以从Perl脚本发送到node.js?

Mik*_*ger 5 javascript perl node.js socket.io

我有一个简单的node.js服务器使用socket.io来监听消息.我正在从Perl脚本向服务器发送消息 - 服务器似乎正在接收消息,但没有识别消息的"通道".如何正确构造要从Perl脚本发送的node.js/socket.io消息?

这是我的node.js服务器:

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);
  });
});
Run Code Online (Sandbox Code Playgroud)

这是我发送消息的Perl脚本的一部分:

#$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;
Run Code Online (Sandbox Code Playgroud)

从Perl脚本收到消息后的服务器日志:

  info  - handshake authorized 1598760311220985572
  debug - client authorized for 
In connection
  debug - xhr-polling received data packet 5:::{'name':'testevent','args':['hello!']}
Run Code Online (Sandbox Code Playgroud)

因此,node.js服务器似乎正在接收消息,但没有识别通道"testevent",因为我希望服务器记录字符串"In testevent",如果它正确地解释了消息.

我是在Perl中正确格式化我的消息,还是我的服务器代码错了?