Nodejs instant chat and nodejs chat room

Source: Internet
Author: User
Tags emit

Nodejs instant chat and nodejs chat room

I always wanted to create an instant chat application. I saw socket. io a few days ago. I felt pretty good. I made some modifications myself and it felt quite good. The example given on the official website is very simple. The following improvements have been made to push historical messages.

Demo address: chat.androiddevelop.cn


Server code:

Var app = require ('express ') (); var http = require ('http '). server (app); var io = require ('socket. io ') (http); var history = new Array (); app. get ('/', function (req, res) {res.sendfile('chat.html ') ;}); io. on ('connection', function (socket) {socket. on ('chat message', function (msg) {io. emit ('chat message', msg); addMsg (msg) ;}); socket. on ('login message', function (msg) {socket. join ('History room '); for (var I = 0; I 


Chat page code:

<! Doctype html> 

In this way, a chat room is implemented. Enter the user name, log on, and the server returns the last 100 messages.


I just downloaded a demo, a chat project written by nodejs. I don't know how to run it. I forgot to give you some advice.

Nodejs?
.Orgdownload node.exe. msi or the installation file in linux

Add node.exe to the environment variable path;
Cmd to your directory
Direct node app. js
OK!

Which of the following is a good chat room for dwr and nodejs?

Nodejs I recommend

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.