Table of contents
【Experiment 1】Build a Socket server
[Experiment 2] Count the number of people online
【Experiment 1】 Build a Socket server
The first step is to enable the telnet command of Windows.
click program
Select options to turn Windows features on or off
Check Telnet client
Click OK to complete
The second step is to create the server.js file with the following code:
run code
Open cmd
input the command
Screenshot of running results:
[Experiment 2] Count the number of people online
Create a new project named name + student number, complete the following server.js code and run it, the result is as shown in the figure:
Write client.js client code, as shown in the figure below:
Select the client port to open in the terminal, open two or more terminal windows, and enter the command node client.js in each window. Screenshot of the result:
|
Screenshot of running results: