Skip to content Skip to sidebar Skip to footer

Node.js: Send Message To Server

I have the following node.js running on my server: var net=require('net'); var util=require('util'); var server=net.createServer(function(conn){ conn.on('connect',function(){

Solution 1:

You've used net.createServer to set up a TCP server. You now need to use net.createConnection to connect to a TCP server.

function sendAMessage(msg) {
  var c = net.createConnection(5000, '172.16.1.218');
  c.on("connect", function() {
    // connected to TCP server.
    c.write(msg);
  });
}

Post a Comment for "Node.js: Send Message To Server"