简体   繁体   中英

Write to Node.js socket

I'm trying to send a string from Node.js to a Java server but nothing will send from the Node.js client unless I call client.end() after. I'm not very experienced with Node.js so any suggestions would help.

var net = require('net');

var client = net.connect(1032, 'localhost')

client.on('connect', function(){
    console.log('connected');
});

client.on('data', function(data){
    console.log(data.toString());
    client.write('test reply');
});

client.on('close', function(){
    client.end();
});
var net = require('net');

var client = net.connect(1032, 'localhost')

client.on('connect', function(){
    console.log('connected');
    client.write('test reply');
});

client.on('data', function(data){
    console.log(data.toString());

});

client.on('close', function(){
    client.end();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM