我内置了使用节点JS和socket.io的应用程序。 这是工作的罚款。 因为我不得不搬到通过安全连接的应用程序,我改变了代码来支持SSL。
但是,现在我不能做一个socket.emit
。 无论是服务器,还是客户端能够发出的消息。
在连接成功建立,但没有得到事后发出的。
下面是代码。
服务器端
var fs = require( 'fs' );
var options = {
key: fs.readFileSync('/etc/httpd/conf.d/ssl/*.xyz.in.key'),
cert: fs.readFileSync('/etc/httpd/conf.d/ssl/xyz.in.crt'),
requestCert: true,
rejectUnauthorized: false // Tried both, with and without this line.
};
var io = require( 'socket.io' ).listen( 8888, options );
io.sockets.on('connection', OnConnection );
io.set("origins", "*:*"); // Tried with and without this line.
// Called when a connection is made with a new Client.
function OnConnection ( socket )
{
console.log( socket.id + " connected" ); // This line gets printed.
socket.on('ev_SendMsgForApproval', OnMsgReceivedForModApproval );
}
function OnMsgReceivedForModApproval( data )
{
console.log( data ); //This does not get executed. :(
}
客户端
var socket = io.connect("https://xyz.com:8888", {secure : true} );
// This message get called for sure.
function OnMsgSendClick()
{
console.log( "Hi" ); // This gets printed on browser's console.
socket.emit( 'ev_SendMsgForApproval', { chatMsg: "Hi" } );
return false;
}
我也曾尝试做从服务器发出,但是该数据,不要么到达客户端。 在调试,我能看到服务器发出的东西,但不到达客户端。
所有这一切都是没有SSL工作正常。
可能是什么问题? 从很长一段时间坚持了这一点。 请帮忙。