ASP.NET 开发聊天室程序(英文)

本文介绍如何使用ASP.NET创建一个完整的聊天应用。该应用利用HTTP协议实现客户端与服务器之间的消息推送,采用HttpApplicationState对象存储数据,并通过Internet Explorer的Web服务特性实现服务器到客户端的消息推送。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ASP.NET 开发聊天室程序(英文)

Introduction: 
In its new avatar, ASP has undergone a metamorphosis. It is no longer confined to simple server-side scripting. It is no more mere bits of HTML contents or data inserted into template HTML code. With it, you can create a full-fledged web application, on the fly, with control over several critical factors.

Anyway, you may ask, what is the difference between a web application and a web page? In server side scripting your role is limited to, and ends with, the rendering of the web page on the client's browser, save that, you can maintain some control over the session and session related variables. On the other hand, for a web application, you approach the whole affair differently - the server is where the action takes place and the page is no longer a simple HTML document. Instead, the web page is a frame on which you create an interactive session between you and the client or between clients among themselves. You compose it from scratch placing elements at the appropriate places, wiring up event handling, storing variables not only for the session state but also for the application state and most importantly controlling flow of information between client and server and from client to client.

The last mentioned ability makes an ASP.NET application into a Peer 2 Peer Networked Application. This article will present you with one such Peer 2 Peer networked application in the form of a Chat application.

Charting the course for chatting 
How do you create a Chat Application? Traditionally, for a chat application, you have to create a server side listener, which requires a server side TCP/IP channel and listens for requests from clients. These requests can be of two types:

Registering a new chat participant 
Passing on chat messages to other chat participants. 
In addition, the server-side program gets a handle to the client object and uses this handle to update chat messages of the participants as well as the list of participants at any given time.

However, in this ASP.NET application, the problem of the Server-side listener can be side stepped, as ASP.NET itself will be the listener. Thus there is no hogging of a TCP/IP channel for a dedicated listener. Since an ASP.NET Application uses the HTTP Protocol and the corresponding Port 80, it is not affected by most of the firewalls, unlike a dedicated chat listener. The HttpApplicationState State Object, provided to us by the NET Framework, solves the problem of sharing information across applications. The options available to us in this regard are:

The HttpApplicationState Object, 
The System.Web.Caching.Cache object, 
Database back end 
The Isolated Storage Dump. 
Whilst the last two options involve Read/Write/IO operations, they are not suitable for a simple chat application where the speed is the essence and there is no great amount of memory involved. The cache object does not provide for locking and may affect synchronization when several users access the page at the same time. Hence, we zero in on the HttpApplicationState object for our data storage. Finally we handle the trickiest question of pushing messages from the server to the client using the web services behavior of Internet Explorer 5.0 and above

There is also no need for support staff starting or ending an application. ASP.NET acts as the master application and is expected to keep going as long as the IIS is running on the Server.

开发语言为Asp,服务器脚本为VBScript; AJAX部分采用JQuery框架,功能代码均为原创;数据库暂时采用ACCESS; --------- 程序功能: 多人即时聊天;新信息声音提示;用户自主选择表情和颜色; 管理员删除信息/踢出用户;高强度管理密码; 数据库压缩; --------- 程序特色 特色?没什么特色!普通的ASP、普通的HTML、普通的JavaScript、还有一个普通的程序编写者; 唯有一点----本程序为原创,没有参考任何其他类似程序 --------- 默认管理员和密码都是admin 一、配置 用记事本打开inc文件夹下的conn.asp,注意如下代码 '聊天室配置 dim admins: admins="anlige,admin" '管理员用户,可自行配置,每个管理员以英文逗号(,)分割;无数量限制 dim pwd: pwd="43894a0e21232f297a57a5a743894a0e4a801fc3" '管理密码,所有管理员使用一个密码!本密码经MD5加密 dim adminToFront: adminToFront=false '管理员登录后是否同步显示到前台(注意,如果设置true,则登录后台的同时登录前台,前台无需再用另一账号),建议设置为false dim msgExpires: msgExpires=300 '信息过期时间,以分钟为单位,系统自动删除过期的信息 dim userExpires: userExpires=20 '用户过期时间,以分钟为单位,系统自动踢出20分钟不发言的用户 '结束配置 配置结束后保存! ____________________________________________________注意(关于密码)_____________________________________________________________________ 密码使用特殊MD5加密算法加密,如要修改密码请按如下方法修改: 假如你的聊天室地址为http://www.***.com/chat/ 访问http://www.***.com/chat/getmd5.asp?string=你要设置的密码,例如http://www.***.com/chat/getmd5.asp?string=admin 然后会显示一串字符串,上例的话会显示43894a0e21232f297a57a5a743894a0e4a801fc3 将inc/conn.asp代码中pwd的值修改为显示的字符串,保存!下次管理员登录就可以用admin这个作为密码登录,建议修改密码后移动getmd5.asp文件 _______________________________________________________________________________________________________________________________________ 二、使用 聊天室默认地址为index.html,直接访问http://www.***.com/chat/index.html即可进入聊天室 具体使用方法请参考help.html 本程序皮肤使用的是QQ2008的聊天皮肤,有兴趣可以自己做皮肤,注意布局! 三、关于 您可以免费使用本程序,请保留代码中的注释信息,谢谢! 请勿利用本程序来实施任何违反法律的行为;否则,一切后果自负! 请保留作者版权信息,尽管不是什么大程序,但作者近期发现很多使用者连开发人都改成自己的名字,这既是对别人劳动成果的不尊重,也是一个人素质的体现
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值