【Computer network】node actual combat

Start the Node command-line parser and try JavaScript
insert image description here
using meta-commands in the Node parser
insert image description here

Write your first server program

var http =require('http');
http.createServer(function (req,res){
    
    
      res.writeHead(200,{
    
    'Contend-Type':'text/plain'});
      res.end('Hello World\n');
   }).listen(8124,"127.0.0.1");
   console.log('Server running at http://127.0.0.1:8124/');

insert image description here
insert image description here

write fun apps

Create a chat server

var net = require('net')
var chatServer =net.createServer()
chatServer.on('connection',function(client){
    
    
  client.write('Hi!\n');
  client.write('Bye!\n');
  client.end()
})
chatServer.listen(9000)

Guess you like

Origin blog.csdn.net/Algernon98/article/details/128695189