当前位置:首页 > 代码 > 正文

asp源代码网站聊天室监听(asp实现一个简易的聊天室)

admin 发布:2022-12-19 06:14 128


本篇文章给大家谈谈asp源代码网站聊天室监听,以及asp实现一个简易的聊天室对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

怎样用asp创建聊天室?(高分)

用ASP建造自己的聊天室

聊天室想必你一定去过吧,但想不想建立自己的聊天室呢?其实这一点都不难,Active Server Script提供了Application对象和Session对象,Application对象代表了一个Active Server应用程序,也就是一个Web网页,Session对象则表示一个用户,代表一个用户对这个页面的一次访问,通过Application对象可以让访问它的所有用户共享信息,并可以在Web服务器运行期间持久地保存数据,而Session对象也可以在用户的一次访问期间持久地保持数据,利用这两个对象,就可以十分方便地建造自己的Chat应用程序。

---- 一、Application对象:

---- 1.属性:Application对象没有内置的属性,但用户可以定义自己的属性:

---- Application(“属性名称”)=值,一旦分配了属性,它就会一直存在,直到Web服务器关闭服务,而且它能被所有用户读取,所以可以用它在用户之间发送谈话内容。

---- 2.方法:当两个用户同时对Application属性的值进行写入操作时,会出现一方的修改被另一方的操作直接覆盖掉的情况,为了避免这种现象,用户可以调用Lock方法进行锁定,这样只有当前用户才能够对Application的属性进行操作,用户完成操作后调用Unlock方法解锁,使得其他用户也可以修改Application的属性。

---- 3.事件:创建Active Server应用程序需要在Web服务器上存放应用程序的虚拟主目录下创建Global.asa文件,它含有Application对象和Session对象的事件处理例程,通常,Application_Onstart事件用来定义应用级的属性。

---- 二、创建一个Chat应用程序:程序运行时如下图所示(略)

---- 1.设置应用程序的变量:这里需建立两个应用程序级的变量,gchars数组用来存放用户的谈话内容,gcounter用做计数器,控制页面的显示行数,在这里我们让页面最多显示最近的10行谈话内容。当应用程序启动时这些变量必须进行初始化,所以它们的创建都要在Global.asa文件中的Application_onstart事件中:

script language="vbscript" runat="server"

sub application_onstart()

dim lchars(10)

application("gchars")=lchars

application("gcounter")=0

end sub

/script

---- 2.确定处理ASP的方式:当用户第一次请求这个ASP文件时,用的是GET方法,然后,当用户输入完谈话内容后提交时用的是POST方法,在这里表单是向自身提交的,所以这个ASP文件会被再次请求,我们通过测试Request . ServerVariales(“Request_Method”)变量来确定文件被请求的方式:IF Request . ServerVariales(“Request_Method”)=“POST” then

---- 3.确定讲话者:当用户第一次提交谈话内容时需输入自己的姓名,一旦在txtname框中输入数据后,程序将建立一个会话级变量来存放用户姓名,并自动显示在txtname框中,用户就不需再次输入了,除非你想用另一个名字加入会谈。

IF len(request(“txtname”)) 0 then

Session(“ssname”)=request(“txtname”)

End if

h5 您的姓名:

input type=“type” name=“txtname”

length=“20” value= %=session(“ssname”)%

----

---- 4.处理用户的谈话内容:首先要确定已经为Chat写入的谈话行数,为方便阅读,在这里将显示行数限定为10行,如果Application(“gcounter”)大于9,则将其置为0,然后将谈话者姓名和内容一起存放到Application(“gchars”)数组中:

Application(“gchars”)

(Application(“gcounter”))=Session(“ssname”)

“:” request(txttalk)

然后将计数器加1:Application(“gcounter”) =Application(“gcounter”)+1

---- 5.将数组内容写入到客户的浏览器中:用户提交谈话内容后,程序必须将数组内容写到客户的浏览器中,让聊天室中的所有人都能看到被提交的谈话内容:

if application("gcounter")=0 then

lstemp=application("gchars")(0)

else

for x=0 to application("gcounter")-1

lstemp=lstemp " br " application("gchars")(x)

next

end if

---- 最后,用Response.write方法将lstemp变量的值写到客户的浏览器中去:

response.write lstemp

---- 下面给出Default.asp的完整代码:

%response.expires=0

response.buffer=true%

html head title Chat sample /title /head

body center

h3 我的聊天室 /h3 /center hr

% if request.servervariables("request_method")="POST" then

if len(request("txtname")) 0 then

session("ssname")=request("txtname")

end if

application.lock

mcounter=application("gcounter")

mchars=application("gchars")

if mcounter 9 then

mcounter=0

end if

mchars(mcounter)=session("ssname")

":" request("txttalk")

mcounter=mcounter+1

application("gcounter")=mcounter

application("gchars")=mchars

application.unlock

end if %

% if application("gcounter")=0 then

lstemp=application("gchars")(0)

else

for x=0 to application("gcounter")-1

lstemp=lstemp " br " application("gchars")(x)

next

end if

response.write lstemp %

hr center

form action="default.asp" method=post name="aspform"

b a href="default.asp"

更新显示 /a /b

h5 发言:

input type="text" name="txttalk" size="70" br

h5 您的姓名:

input type="text" name="txtname" length="20"

value= %=session("ssname")%

input type="submit" name="cmdpost" default="true" value="发送"

/form /center /body /html

---- 以上代码在NT4.0、IIS4.0、IE4.0中和Pwin98、PWS、IE4.0中分别运行通过。

本人下了一个ichat视频聊天室asp源程序,请问如何使用啊!!

如果是ASP

的程序

你需要安装系统盘自带的IIS组件

或者你把系统盘放近光区

你在控制面板

--添加删除程序

--添加删除WINDOWS组件--选择安装IIS

安装完整后

把你的原程序考到C:\Inetpub\wwwroot目录下

然后在运行里打inetmgr---回车

在默认网站中

你就可以浏览你的程序了

用ASP该怎么做聊天室?设计思路?

chat.asp

%@ language=JSCRIPT %

html

head

meta http-equiv="refresh" content="10; charset=gb2312;urll=chat.asp"

title聊天页面/title

/head

body bgcolor="#FFFFFF" text="#000000"

p align="left"font color="#303740" size="+1"欢迎来到蚂蚁聊天室/font/p

ifont color="#990066"现在有/font/i

% Response.Write(Application("counter2"));%

font color="#996600"i位用户在线/i/font

hr

div style="width: 304px; height: 220px; background-color:#C0C0C0" id="layer1"

br

%

Application.Lock();

var s="user";

var speach;

if(Request.Form("speach").count!=0)

{

speach=Session("name")+""+"说到:"+Request.Form(1);

}

else

{

speach="欢迎"+Session("name")+"进入本聊天室!";

}

for(var i=0;i15;i++)

{

var t=i;

var tt=i+1;

Application(s+t.toString())=Application(s+tt.toString());

}

Application(s+"15")=speach;

Application.Unlock();

%

%

Application.Lock();

var s="user";

for(var i=0;i16;i++)

{

t=i;

Response.Write(Application(s+t.toString()));

%

br

%

}

Application.Unlock();

%

/div

/body

/html

login.asp

% language=JSCRIPT%

html

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312"

title用户登录/title

/head

body bgcolor="#FFFFFF" text="#000000"

form name="usrerForm" method="post" action="deallog.asp"

p聊友名:

input type="text" name="textfield"

/p

p

input type="submit" name="Submit" value="登录"

/p

/form

/body

/html

send.asp

html

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312"

/head

body bgcolor="lightblue"

form method=post action="chat.asp" target="show"

%=Session("name")%:

input name="speach" type=text size=50

select size="1" name="mycolor"

option value="red"红色/option

option value="blue"蓝色/option

option value="green"绿色/option

/select

input type=submit value="SEND"

/form

/body/html

dispose.asp

html

head

title聊天页面/title/head

frameset rows="*,100"

frame name="show" src="chat.asp"

frame name="say" src="send.asp"

/frameset

/html

deallog.asp

%@ language=VBSCRIPT%

%

name=request.form("textfield")

session("name")=name

response.redirect("dispose.asp")

%

Global.asa

script language="JScript" runat="server"

function Application_OnStart()

{

Application("talk")="";

Application("counter")=0;

Application("counter2")=0;

}

function Session_OnStart()

{

Session("username")="无名氏";

Session("name")="无名氏";

Session("no")="NOT";

Application("counter")=Application("counter")+1;

Application("counter2")=Application("counter2")+1;

}

function Session_OnEnd()

{

Application("counter")=Application("counter")-1;

Application("counter2")=Application("counter2")-1;

}

/script

你借鉴一下,可以用就拿去.有很多不完善的要多改进.思路吗?也是从中来的.

meta http-equiv="refresh" content="10; charset=gb2312;urll=chat.asp"刷新的句子.

求个这样的一个asp聊天室完整源代码

哎 兄弟 我搞个钓鱼网也快搞疯了 学好多东西 一下三剑客 一下E语言 到现在都不知道学那个好 买了域名金额FTP空间都不知道买来干什么 花了几百元 哎!听我的 好好去学怎么编代码吧! 没人给你代码的~

跪求一套完整的asp简易的聊天室!!

以下是一个简易聊天室代码,代码摘自网上,可以做为参考。

%@ Language=VBScript %

%

Response.Buffer=true ' 设 置 输 出 缓 存,用 于 显 示 不 同 页 面。

On error resume next ' 忽 略 程 序 出 错 部 分

If Request.ServerVariables("Request_Method")="GET" then

'------------------------

' 客 户 登 陆 界 面 

'------------------------

%

form method="POST" action="luo40.asp"p

input type="text" name="nick" size="20" value="nick" style="background-color: rgb(192,192,192)"br

input type="submit" value=" 进 入 聊 天 室 " name="B1" style="color: rgb(255,255,0); font-size: 9pt; background-color: rgb(0,128,128)"

pinput type="hidden" name="log" size="20" value="1"br/p

/form

%

Response.End ' 结 束 程 序 的 处 理

Else

Response.clear ' 清 空 缓 存 中 的 内 容

dim talk

If Request.Form("nick")"" then

' 判 断 客 户 是 是 否 在 聊 天 界 面 中 

Session("nick")=Request.Form("nick")

End If

'------------------------

'客 户 聊 天 界 面 

'------------------------

%

form method="POST" action="luo40.asp" name=form1 p%=Session("nick")% 说 话:input type="text" name="talk" size="50"br

input type="submit" value=" 提 交 " name="B1"

input type="reset" value=" 取 消 " name="B2"/p

/form

A HREF="luo40.asp" 离 开 /abrbr

%

If Request.Form("log")1 then

If trim(Request.Form("talk"))="" then

' 判 断 用 户 是 否 没 有 输 入 任 何 内 容 

talk=Session("nick")" 沉 默 是 金。"

Else

talk=trim(Request.Form("talk"))

' 去 掉 字 符 后 的 空 格 

End If

Application.lock

Application("show")="table border='0' cellpadding='0' cellspacing='0' width='85%'trtd width='100%' bgcolor='#C0C0C0'/td/trtrtd width='100%'font color='#0000FF' 来 自 "Request.ServerVariables("remote_addr")" 的 "Session("nick")time" 说:/font"talk"/td/trtrtd width='100%' bgcolor='#C0C0C0'/td/tr/tablebr"Application("show")

Application.UnLock

Response.Write Application("show")

End If

End If

%

求网页聊天室asp源码

1.创建index.asp页面

html

frameset rows="60,*"

frame name="say" src="say.asp"

frame name="message" src="message.asp"

/framesetnoframes/noframes

/html

2.创建say.asp页面

html

body

form name="form1" method="post" action=""

昵称:input type="text" name="txtName" size="10"

发言:input type="text" name="txtSay" size="30"

input type="submit" value=" 发送 "

/form

%

'如果提交了表单,就将发言内容添加到Application对象中

If Trim(Request.Form("txtName"))"" And Trim(Request.Form("txtSay"))"" Then

'下面先获取发言人的IP地址

User_ip=Request.ServerVariables("Remote_Addr")

'下面获取本次发言字符串,包括发言人和发言内容

Dim strSay

strSay="来自于"User_ip "的" Request.Form("txtName") "在" Now() "说:" Request.Form("txtSay") "br"

'下面将本次发言添加到聊天内容中

Application.Lock '先锁定

Application("strChat")=strSay Application("strChat")

Application.Unlock '解除锁定

End if

%

/body

/html

3.创建message.asp页面

html

head

title显示发言页面/title

meta http-equiv="refresh" content="5"

/head

body

% Response.Write Application("strChat") '显示聊天内容 %

/body

/html

关于asp源代码网站聊天室监听和asp实现一个简易的聊天室的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/3658.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载