Skip to content

Instantly share code, notes, and snippets.

@emschwartz
Created April 19, 2018 18:34
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save emschwartz/f62e8c7bb9d3d0a82b756a2d7095de6f to your computer and use it in GitHub Desktop.
Socket test
const net = require('net')
const server = net.createServer((connection) => {
connection.on('close', () => console.log('server close'))
connection.on('end', () => console.log('server end'))
connection.on('error', () => console.log('server error'))
connection.on('finish', () => console.log('server finish'))
connection.on('data', (chunk) => console.log('server got data', chunk.length))
//setTimeout(() => console.log('reading data', connection.read(1000)), 10)
//connection.write(Buffer.alloc(10000000))
})
server.listen(8124, () => {
const connection = net.createConnection(8124)
connection.on('connect', () => {
connection.write(Buffer.alloc(10000000))
console.log('client wrote data')
connection.end()
console.log('client called end')
})
connection.on('close', () => console.log('client close'))
connection.on('end', () => console.log('client end'))
connection.on('error', () => console.log('client error'))
connection.on('finish', () => console.log('client finish'))
//connection.on('data', (chunk) => console.log('client got data', chunk.length))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment