First Chat!

Let’s test the new functionality. Make sure that nodemon has reloaded your code. (If you need to, you can manually stop nodemon with Control-C and restart it with npm run dev.)

Open a third terminal window and run the command wscat -c http://localhost:3001. (You should have one terminal running nodemon and two running wscat.) Enter some chat messages in the two windows connected to the server.

After you have chatted with yourself for a bit, open a fourth terminal and run wscat -c http://localhost:3001. This chat client should be sent all the previous messages.

If everything went well, you should see something like Figure 16.4.

Figure 16.4  Chatting with some friends

Chatting with some friends

Congratulations! You have written a fully functional chat server using WebSockets – and it took less than two dozen lines of JavaScript.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.5.201