分享
 
 
 

在线聊天 如何实现?

王朝知道·作者佚名  2010-10-13
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

像占座上的那种在现聊天的很简洁,那是如何实现的呢?

现在有一个网站(php),同时大约有10人以内在线的。

应该通过什么语言实现》或者哪里有这方面的代码?

參考答案:

用ASP和dreamerweaver可以啊

<!--#include file="../conn/conn.asp"-->

<%

dim info

dim changed

if Request.ServerVariables ("REQUEST_METHOD")="GET" then

UserID=Request.QueryString ("user")

myname=session("myname")'Request.QueryString ("roomname")

end if

if Request.ServerVariables ("REQUEST_METHOD")="POST" then

yinword=request.form("yinword")

myname=Request.Form ("userid")

UserID=myname

myroom=session("myroom")'Request.Form ("roomname")

mynickname=Request.Form ("mynickname")

newsql="update chatUserOnLine set TimeLastTalking='" & now & "' where UserID='" & UserID & "'"

conn.Execute (newsql)

Application.Lock

if left(Request.Form ("yinword"),1)="/" then

command=Request.Form ("yinword")

select case left(Request.Form ("yinword"),2)

case "/j" '加入新房间

newroom=trim(mid(Request.Form ("yinword"),4))

newsql="select RoomName,IfLocked,WhoCreate from chatRoomInfo where RoomName='" & newroom & "'"

set newrecord=conn.Execute (newsql)

'Response.Write newrecord("RoomName")

if newrecord.bof or newrecord.eof then

application(UserID)="没有这个房间号!<br><br>" & application(UserID)

elseif newrecord("IfLocked")=true then

newsql="select UserID from chatUserOnLine where RoomName='" & newroom & "' and UserID='" & newrecord(2) & "'"

set myrecord=conn.Execute (newsql)

if not myrecord.BOF then

application(UserID)="这个房间已经上锁,不能进入!<br><br>" & application(UserID)

else

Create_Leaved=true

newsql="update chatRoomInfo set IfLocked=0 where RoomName='" & newroom & "'"

end if

elseif Create_Leaved=false then

'changed=true

application(UserID)=application(newroom)

newsql1="select UserID from chatUserOnLine where RoomName='" & newroom & "'"

set targ=server.CreateObject ("ADODB.Recordset")

targ.Open newsql1,conn,1,3

do while not targ.eof

tempname=cstr(targ("UserID"))

'Response.Write targ("UserID")

if tempname<>UserID then

application(tempname)="<br>" & mynickname & "大摇大摆地进来了!(请刷新)<font color=blue size=1>(" & time() & ")</font><br><br>" & application(tempname)

end if

targ.movenext

loop

newsql3="update chatRoomInfo set HowManyUsers=HowManyUsers+1 where RoomName='" & newroom & "'"

conn.Execute (newsql3)

newsql4="update chatRoomInfo set HowManyUsers=HowManyUsers-1 where RoomName='" & myroom & "'"

conn.Execute (newsql4)

newsql2="update chatUserOnLine set RoomName='" & newroom & "' where UserID='" & UserID & "'"

conn.Execute (newsql2)

application(UserID)="你已经进入了" & newroom & "房间<br><br>" & application(UserID)

session("myroom")=newroom

changed=true

targ.Close

set targ=nothing

end if

case "/r" '查看聊天室房间信息

newsql="select * from chatRoomInfo"

set newrecordseyinword=conn.Execute (newsql)

do while not newrecordseyinword.eof

info=info & newrecordseyinword("RoomName") & "--" & newrecordseyinword("HowManyUsers") & "--" & newrecordseyinword("Topic") & "--" & newrecordseyinword("IfLocked") & "--" & newrecordseyinword("WhoCreate") & "<br>"

newrecordseyinword.movenext

loop

'Response.Write info

application(UserID)=info & "<br>" & application(UserID)

case "/w" '查看聊天室成员信息

if len(trim(Request.Form ("yinword")))=2 then

newsql="select * from chatUserOnLine"

set newrecordset2=conn.Execute (newsql)

do while not newrecordset2.eof

info=info & newrecordset2("UserId") & "--" & newrecordset2("RoomName") & "--" & newrecordset2("IpAdd") & "--" & newrecordset2("TimeLogin") & "<br>"

newrecordset2.movenext

loop

application(UserID)="<font color=red>"& info & "<br>" & application(UserID)

else

if right(left(Request.Form ("yinword"),3),1)<>":" then

info="命令行输入错误<br>"

application(UserID)=info & application(UserID)

else

temproom=mid(trim(Request.Form ("yinword")),4)

newsql="select RoomName from chatRoomInfo where RoomName='" & temproom & "'"

set newrecord3=conn.Execute (newsql)

if not newrecord3.bof then

newsql="select * from chatUserOnLine where RoomName='" & temproom & "'"

set newrecordset2=conn.Execute (newsql)

if newrecordset2.bof then

application(UserID)="<br>该房间暂时没有人!<br><br>" & application(UserID)

else

do while not newrecordset2.eof

info=info & newrecordset2("UserId") & "--" & newrecordset2("RoomName") & "--" & newrecordset2("IpAdd") & "--" & newrecordset2("TimeLogin") & "<br>"

newrecordset2.movenext

loop

application(UserID)="<br>" & info & "<br>" & application(UserID)

end if

else

info="<br>没有<font color=red><strong>" & temproom & "</strong></font>这个房间!<br>"

application(UserID)=info & application(UserID)

end if

end if

end if

case "/l" '锁住本房间

'lockroom=mid(Request.Form ("yinword"),4)

newsql="select WhoCreate from chatRoomInfo where WhoCreate='" & UserID & "' and RoomName='" & session("myroom") & "'"

set newrecordset=conn.Execute (newsql)

if newrecordset.bof then

application(UserID)="不好意思,你无权锁住这个房间!<br><br>" & application(UserID)

else

newsql="update chatRoomInfo set IfLocked=1 where RoomName='" & session("myroom") & "'"

conn.Execute (newsql)

application(UserID)="你已经锁住了这个房间!<br><br>" & application(UserID)

end if

case "/u"'解开房间

newsql="select WhoCreate from chatRoomInfo where WhoCreate='" & UserID & "' and RoomName='" & session("myroom") & "'"

set newrecordset=conn.Execute (newsql)

if newrecordset.bof then

application(UserID)="不好意思,你无权解开这个房间或者不在那个房间!<br><br>" & application(UserID)

else

newsql="update chatRoomInfo set IfLocked=0 where RoomName='" & session("myroom") & "'"

conn.Execute (newsql)

application(UserID)="你已经解开了这个房间!<br><br>" & application(UserID)

end if

case "/c"

application(session("myname"))=""

case "/b" '退出聊天室

%>

<script language="javascript">

<!--

top.location.href ="chatbye.asp"

//-->

</script>

<%

session.Abandon

Response.End

case "/h" '显示帮助系统

info="/h---显示帮助提示<br>"

info=info & "/j:roomname---加入新的房间<br>"

info=info & "/r---查看当前房间信息<br>"

info=info & "/w:roomname---查看当前用户情况<br>"

info=info & "/l--锁住当前房间,只有创建者才能锁住<br>"

info=info & "/b--退出聊天室<br>"

info=info & "/u--解开某个房间<br>"

info=info & "/t:modifytopic--修改话题,只有创建者才能修改<br>"

info=info & "/c--清除聊天内容<br>"

application(UserID)= "<br>" & info & "<br>" & application(UserID)

case "/t"'更改房间话题

if right(left(command,3),1)<>":" then

application(UserID)="<br>命令输入错误!<br><br>" & application(UserID)

else

newsql="select WhoCreate from chatRoomInfo where WhoCreate='" & UserID & "' and RoomName='" & session("myroom") & "'"

set newrecordset=conn.Execute (newsql)

if newrecordset.bof then

application(UserID)="不好意思,你无权修改这个房间的话题!<br><br>" & application(UserID)

else

newsql="update chatRoomInfo set Topic='" & mid(command,4) & "' where RoomName='" & session("myroom") & "'"

conn.Execute (newsql)

newsql="select UserID from chatUserOnLine where RoomName='" & session("myroom") & "'"

set t_newrecordset=conn.Execute (newsql)

do while not t_newrecordset.eof

application(t_newrecordset(0))="房间话题被修改为<font color=#ff0000>" & mid(command,4) & "</font>!<br><br>" & application(t_newrecordset(0))

t_newrecordset.movenext

loop

t_newrecordset.close

set t_newrecordset=nothing

'application(UserID)="你已经修改这个房间的话题为<font color=vbpurplea>" & mid(command,4) & "</font>!<br><br>" & application(UserID)

end if

end if

case else

application(UserID)= "<br>没有这个命令,请用/h查看帮助<br>" & application(UserID)

end select

else

if request.form("targ")<>"all" then

id_name=Request.Form ("targ")

'Response.Write id_name

temppos=instr(1,id_name,",",1)

yourid=mid(id_name,1,temppos-1)

yournickname=mid(id_name,temppos+1)

end if

set myrecord=server.CreateObject ("ADODB.Recordset")

mysql="select * from chatUserOnLine where RoomName='" & myroom & "'"

myrecord.Open mysql,conn,1,3

'application.lock

if request.form("targ")="all" or request.form("siliao")<> "ON" then

if request.form("targ")="all" then

tempstr="<font color='" & request.form("color1") & "'>" & mynickname & Request.Form ("facing") & "说: " & request.form("yinword") & "</font><font color=blue size=0.5>(" & time() & ")</font><br>"

else

tempstr="<font color='" & request.form("color1") & "'>" & mynickname & "悄悄对" & yournickname & Request.Form ("facing") & "说: " & request.form("yinword") & "</font><font color=blue size=0.5>(" & time() & ")</font><br>"

end if

do while not myrecord.EOF

application(myrecord("UserId"))=tempstr & application(myrecord("UserId"))

myrecord.MoveNext

loop

application(myroom)=tempstr & Application(myroom)

'if len(application(myroom))>1000 then

'

' length2=len(application(myroom))

' temppos=instrrev(application(myroom),"<br>",length2)-1

' application(myroom)=mid(application(myroom),1,temppos)

' end if

' application(UserID)= "<br>len(application(myroom))" & len(application(myroom)) & "<br>" & application(UserID)

' application(UserID)= "<br>length2" & length2 & "<br>" & application(UserID)

' application(UserID)= "<br>temppos" & temppos & "<br>" & application(UserID)

else

tempstr="<marquee border='0' behavior='alternate'><font color='" & request.form("color1") & "'>" & mynickname & "对" & yournickname & Request.Form ("facing") & "说:" & request.form("yinword") &"</font></marquee>" &"<font colovrr=blue size=0.5>(" & time() & ")</font><br>"

application(yourid)=tempstr & application(yourid)

application(myname)=tempstr & Application(myname)

end if

'if len(application(myname))>20000 then

' length1=len(application(myname))

' temppos=instrrev(application(myname),"<br>",length1-4)-1

' application(myname)=mid(application(myname),1,temppos)

'end if

application.unlock

end if

'Response.Write (application(UserID))

Response.Write application(UserID)

else

Response.Write application(UserID)

end if

conn.Close

set conn=nothing

if changed=true then

%>

<script language="javascript">

<!--

parent.frames[1].location.href="chatsend.asp"

//-->

</script>

<%

end if

%>

<html>

<head>

<meta http-equiv="refresh" content="10;url=chatcontent.asp?user=<% =UserID %>">

<title>聊天内容</title>

<base target="ltop">

</head>

<body bgcolor="rgb(254,252,237)">

</body>

</html>

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有