Created
October 16, 2018 09:42
-
-
Save getnamo/396577cb4988188e291774ac7e368368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** from: https://nodejs.org/api/net.html#net_net_createconnection_options_connectlistener */ | |
const net = require('net'); | |
const port = 3000; | |
const client = net.createConnection({ port: 3000 }, () => { | |
console.log('connected to server!'); | |
//pipe immediately something back | |
client.write('Hello from TCP client!\r\n'); | |
//send delayed data test | |
setTimeout(()=>{ | |
console.log('sent!'); | |
client.write('and some delayed text.\r\n'); | |
}, 2000); | |
}); | |
client.on('data', (data) => { | |
console.log(data.toString()); | |
client.end(); | |
}); | |
client.on('end', () => { | |
console.log('disconnected from server'); | |
}); | |
client.on('error',(err)=>{ | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment