I'm trying to create a simple TCP server (node.js). Actually, there is no problem with the code:

var net = require('net'); var HOST = '0.0.0.0'; var PORT = 6969; // Create a server instance, and chain the listen function to it // The function passed to net.createServer() becomes the event handler for the 'connection' event // The sock object the callback function receives UNIQUE for each connection net.createServer(function(sock) { // We have a connection - a socket object is assigned to the connection automatically console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort); // Add a 'data' event handler to this instance of socket sock.on('data', function(data) { console.log('DATA ' + sock.remoteAddress + ': ' + data); // Write the data back to the socket, the client will receive it as data from the server sock.write('You said "' + data + '"'); }); // Add a 'close' event handler to this instance of socket sock.on('close', function(data) { console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort); }); }).listen(PORT, HOST); console.log('Server listening on ' + HOST +':'+ PORT); 

The problem is that it should be placed on a VPS (Ubuntu 14 (64-bit). All attempts to send a packet to xxxx:6969 do not work. The server is started with the nodejs file.js . It prints a confirmation (Server listening on ...) and silence.

  • Is the specified port available from the outside? Tried to send tcp requests to the server from the same machine via telnet? - Dmitriy Simushev
  • Greetings. This question is about administration and requires knowledge of server settings. It is best to contact the hosting support service. - Maxim Bogdanov
  • Yes, the problem is in the server. Php script sends messages without problems. - Leonid Malyshev

1 answer 1

 iptables -I INPUT -p tcp -m tcp --dport 6969 -j ACCEPT 

solved the problem