发信人: marsz() 
整理人: workingnow(2002-10-30 14:00:01), 站内信件
 | 
 
 
前几天有个网友提问出此问题,我想当然的给他了回答,但是经过自己试验以后 并不很理想,所以想和大家探讨一下聊天室编程的方法。
 
 大家都会喜欢不是依靠刷新叶面来post message的聊天室,我想要达到这种效果 的方法只有一个,延迟叶面的下载,也就是说让叶面处于不断的下载状态,所以 可以用循环的方法判断,每隔一段时间,检查一下有没有新的发言,ASP中没有定 时器的方法,所以只有自己写,以下是我写的一个简单的定时器:
 
 <%
 	Server.ScriptTimeOut =3600
 	myTime=Time()
     delayTime=1/(3600*24)'延迟时间,1秒
     thisTime=Time()
     
     while myTime<(thisTime+1/144)'循环时间10分钟
     	nowTime=Time()
     	while myTime<(nowTime+delayTime)
     		myTime=Time()
     	wend
     	response.write myTime & " "'每隔1秒打印一次当前时间
     wend
 %>
 
 但是我发现这种循环很占用资源,搞不好就会让IIS Down掉,但是实在想不出更 好的办法,我做了一个简单的界面,达到最简单的聊天室效果,但是这个东西太 耗费资源,根本不实用,实际上用什么语言是不重要的,如php\perl遇到的问题 也是一样,关键在于技巧,不知道哪为高手有这方面的经验之谈,不妨说出来听 听,大家共同进步嘛,也希望斑竹能给点建议,Thank you very much!!!
 
 有兴趣的话你可以试试,有3个文件:index.htm、foot.asp和head.asp,下面是 代码:
 
 index.htm
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 <html>
 
 <head>
 <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
 <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
 <meta name="ProgId" content="FrontPage.Editor.Document">
 <title>New Page 2</title>
 </head>
 
 <frameset rows="*,20%">
   <frame name="main" target="footnotes" src="head.asp">
   <frame name="footnotes" src="foot.asp">
   <noframes>
   <body>
 
   <p>此网页使用了框架,但您的浏览器不支持框架。</p>
 
   </body>
   </noframes>
 </frameset>
 
 </html>
 
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 foot.asp
 
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 <html>
 
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
 <meta name="ProgId" content="FrontPage.Editor.Document">
 <title>New Page 4</title>
 </head>
 
 <body>
 
 <form method="GET" action="foot.asp">
   <p><input type="text" name="chatword" size="20"><input type="submit"  value="提交" name="B1"><input type="reset" value="全部重写" name="B2" ></p>
 </form>
 
 <%
 	
 	if request("chatword")<>"" then
 		Application("chatword")=request("chatword")
 	end if
 %>
 
 </body>
 
 </html>
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 head.asp
 
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 <html>
 
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
 <meta name="ProgId" content="FrontPage.Editor.Document">
 <title>New Page 3</title>
 <base target="footnotes">
 </head>
 <body>
 <p>
 hello
 <%
 	Server.ScriptTimeOut =3600
 
 	myTime=Time()
     delayTime=1/(3600*24)
     thisTime=Time()
     
     while myTime<(thisTime+1/144)
     	nowTime=Time()
     	while myTime<(nowTime+delayTime)
     		myTime=Time()
     	wend
 	if Application("chatword")<>Application("preword") then
 		response.write "<p>" & myTime & " " & Application("chatword")
 	end if
 	Application("preword")=Application("chatword")
     wend
 
 		
 %>
 </p>
 </body>
 
 </html>
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  -- 天上星 亮晶晶 永灿烂 保安宁
  ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.106.14.121]
  | 
 
 
 |