Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const net = require('net');
  2. const http = require('http');
  3.  
  4. http.createServer((req, res) => {
  5.   // console.log(req)
  6.   console.log('REQ, RES')
  7.   res.end('RESPONSE OK')
  8. }).listen(1337)
  9.  
  10. const socket = net.createConnection({ port: 1337 }, () => {
  11.   console.log('Connected')
  12.   // Wrong
  13.   socket.end('GET / http/1.1\r\nConnection: close\r\n\r\n')
  14.   // Correct
  15.   // socket.end('GET / HTTP/1.1\r\nConnection: close\r\n\r\n')
  16. })
  17.  
  18. socket.on('data', (data) => {
  19.   console.log('DATA')
  20.   console.log(data.toString())
  21. })
  22. socket.on('end', () => {
  23.   console.log('END')
  24. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement