用node.js搭建web聊天室

来源:互联网 发布:redis数据库叫什么 编辑:程序博客网 时间:2024/05/16 09:46
此处选用的系统是 CentOS 5.4 x86_64
一、 安装node.js
1、 下载node.js源码包
地址http://nodejs.org/download/ 这里有最新版本的node.js对应各个操作系统的二进制文件或者源码包,请自行选择,此处我们选源码编译安装,所以下载源码包。
现在最新版已经是v0.10.3了。

取得tar包的url,敲命令
enter image description here
图表 1复制链接地址

wget http://nodejs.org/dist/v0.10.3/node-v0.10.3.tar.gz

在linux中用wget下载
2、 编译安装
•解压

tar zxvf node-v0.10.3.tar.gz

•编译安装
./configure --prefix=/usr/local/node #prefix参数指定要安装到的路径,如果这个命令执行失败,最常见的原因是,当前python版本太低。此处最初也碰到了这个问题,把python2.4升级到python2.7后解决这个问题。

make #这个命令要花些时间,此时可以去沏杯茶喝make install

此时运行命令 node –v ,若显示如下:
v0.10.3
则表示安装node.js成功。
二、 安装基于node.js的web聊天室demo
下载源码包
在CSDN上,http://download.csdn.net/download/wanglei_134/4593099
感谢 @wanglei_134同学
下载完成后,解压

unzip chat.zip

注意看你的系统是否安装有unzip这个命令。
进入目录

cd chat/chat/

运行命令

node chat.js

这时你就能看到如下界面了
enter image description here
在浏览器地址栏中,如果你是安装在本地机器上,则输入h ttp://127.0.0.1:3000;如果是在内部网服务器上,则输入相应服务器IP,h ttp://hostIp:3000,就能看到聊天室登陆界面啦!
enter image description here
enter image description here
enter image description here
enter image description here
当有客户端发起连接时,后台会有调试日志输出
enter image description here

0 0
原创粉丝点击