建立TCP的链接
1 发送消息的服务
2 接收消息
2 建立http的链接让浏览器进行访问
import net from 'net'
const html = `<h1>TCP</h1>`
const respinseHeaders = [
'HTTP/1.1 200 OK',
'Content-Type:text/html',
'Content-Length':' + html.length,
'\r\n',
html
]
const http = net.createServer(socket=>{
socket.on('data',(e)=>{
if(/GET/.test(e.toString())){
socket.write(responseHeaders,join('\r\n'))
socket.end()
}
console.log(e.toString())
})
})
http.listen(80,()=>{
console.log('Server is listening on port 80')
})