0

I'm making a api service which connects to a SSL TCP server to retrieve data. I first made this api in C# and it works. Later I ported it to node.js to take the advantages of node.js. However I couldn't connect to the server.

Target : Host : prodtw.lol.garenanow.com Port : 2099

Code in C# which can connect to the server and works perfectly:

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);

Code in node.js, which couldn't connect to the SSL TCP server :

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.
});

After running the above node.js code, it never shows "Successfully connected". It only shows "Connecting" and stucks at tls.connect...

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Using your code with port 443 and host 'encrypted.google.com', it runs fine and returns 'Successfully connected!'. I would venture a guess that either Node's TLS doesn't like the port (longshot, but possible), or the server is not responding to the request. Is your C# code working _currently_? – ascary May 31 '15 at 04:19
  • @ascary yes my c# code working corretly –  May 31 '15 at 04:29
  • @adamdc78 thats my typing mistake –  May 31 '15 at 04:29
  • I would suggest validating your server is accessible. I am getting an error with both your C# code and your NodeJS code with the server you specify above. Changing to port 443 and host encrypted.google.com, connection succeeds for both NodeJS and C#. – ascary Jun 01 '15 at 19:11
  • 1
    @ascary I know the answer now. I've test the connection of the server and I found that the server only accepts IPs from Honk Kong and Taiwan. That's the server's problem. –  Jun 02 '15 at 07:44

0 Answers0