Build an instant messaging system based on socket. io and node. js _ node. js-js tutorial

Source: Internet
Author: User
Socket. IO is a websocket library, including the client js and the server nodejs. Official Address: socket. io uses socket. io and nodejs to build a websocket Server

Socket. io can not only build the websocket service of the client, but also support the websocket of the nodejs server.

Next let me introduce how to install and configure nodejs.

Go to http://nodejs.org/javasdownloadto download the msifile. Always click next to install. The final file is automatically installed in the C: \ nodejs directory.

After the installation is complete, environment variables are automatically configured. If no automatic configuration is available, manually add C: \ nodejs \ in the path \.

After the installation is complete, you need to configure npm to manage the node. js module.

Install git to install npm in window.

After installing git, open gitbush. Perform the following steps:

git config --system http.sslcainfo /bin/curl-ca-bundle.crtgit clone --recursive git://github.com/isaacs/npm.gitcd npmnode cli.js install npm -gf

The first one is that there is no prompt for the settings. The second step will go to github to download npm files and progress, and the fourth step is to install npm to node. js will copy several cmd files and the mode_modules folder to the nodejs directory.

In this way, npm is configured.

If you need to install any modules, enter npm install ***.

If there is no npm or windows users can use github to download socket. io and put it into the node_modules folder. For detailed configuration, refer to: nodejs Tutorial: configure the windows directory structure of nodejs.exe.

Install socket. io in nodejs

Use the node plug-in management package and run the following command to install socket. io successfully.

npm install socket.io

An example of socket. io implementation

Client code:

       

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.