Answer the question
In order to leave comments, you need to log in
Why can't create a TCP client?
var net = require('net'),
clientSocket = new net.Socket();
clientSocket.setEncoding('utf8');
clientSocket.connect('8080', 'localhost', function(){
console.log('Connected!');
clientSocket.write('Hello!');
});
clientSocket.on('data', function(data) {
console.log('data: ' + data);
});
clientSocket.on('close', function() {
console.log('Bye!');
});
Answer the question
In order to leave comments, you need to log in
There, in the function callback, there is an argument responsible for describing errors. Use it to understand why.
Also make sure that the server is up on the right port and on the right host. Well, that he is raised. The easiest way is through netcat.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question