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