我正在建立一个连接到SSL TCP服务器以检索数据的api服务。我首先在C#中创建了这个api并且它有效。后来我将它移植到node.js以利用node.js的优点。但是我无法连接到服务器。
目标: 主持人:prodtw.lol.garenanow.com 港口:2099
C#中的代码,可以连接到服务器并完美运行:
TcpClient client;
try
{
client = new TcpClient("prodtw.lol.garenanow.com", 2099);
Console.WriteLine("Connected to server.");
}
catch
{
Console.WriteLine("Error");
return;
}
SslStream sslStream = new SslStream(client.GetStream(), false, AcceptAllCertificates); //AcceptAllCertificate does nothing, just return true
var ar = sslStream.BeginAuthenticateAsClient("prodtw.lol.garenanow.com", null, null);
using (ar.AsyncWaitHandle)
{
if (ar.AsyncWaitHandle.WaitOne(-1))
sslStream.EndAuthenticateAsClient(ar);
}
// Connected, write something
byte[] handshakePacket = new byte[1537];
sslStream.Write(handshakePacket);
node.js中的代码,无法连接到SSL TCP服务器:
var tls = require('tls');
console.log('Connecting');
var stream = tls.connect(2099, "prodtw.lol.garenanow.com", function() {
console.log('Successfully connected!'); //Never print this message.
});
运行上面的node.js代码后,它永远不会显示“Successfully connected”。它只显示“正在连接”并卡在tls.connect ...