多对一的聊天是怎么弄的

来源:互联网 发布:阿卡索外教网 知乎 编辑:程序博客网 时间:2024/04/29 03:49
  首页 - ASP.NET - 正文 ASP.NET讨论区 收藏本站  
<iframe id="baiduframe" border="0" align="center" marginwidth="0" framespacing="0" marginheight="0" src="http://unstat.baidu.com/bdun.bsc?tn=freevod&amp;csid=103&amp;rkcs=1&amp;bgcr=FFFFFF&amp;ftcr=000000&amp;rk=1&amp;bd=0&amp;bdas=0" frameborder="0" width="670" scrolling="no" height="40"></iframe>

这样的多对一的聊天是怎么弄的,求大家给个思路,谢谢!

 作 者:flashasp(flashasp)
 时 间:2005-12-21 8:55:39
http://bj1.webeye.net.cn/chatet/aspx/visit/ChatC.aspx?id=4vtvtzfszydfus2cdd1ruxfo&keycode=1&state=N&coprname=广州资源软件有限公司&listresearch=1
这个好象也是。NET做的,大家觉得是怎么弄的,谢谢指点。。。

回复人:远方(califord)2005-12-21 9:07:10
这是一个客服哟,以前也见过.差不多是将甩有客户接到一个ID上聊天,但是我不清楚,关注一下
回复人:醉龙(zuilong1208)2005-12-21 9:21:40
关注
回复人:没有烟抽的日子.(xczgb)2005-12-21 9:47:59
共同关注。。
回复人:碧海(wokagoka)2005-12-21 9:54:13
站内通讯~~用最笨的数据库方法吧,这个比较简单!!
或者做成主机监听模式,一有数据通讯就建立链接到主机之外的一台机器上,建立外网与内网的通讯……
回复人:萨达姆(nameone)2005-12-21 9:57:14
學習
回复人: 二级(初级) user2 100 32797282 4471611839186zhouheng1234560 2005-12-21 10:06:31 水温没调好(nosad)2005-12-21 10:07:46
想知道~~
回复人:雨花中的小皮鞋(seaonce)2005-12-21 10:14:21
从表面上看是用的框架
回复人:发粪涂墙(jc15271149)2005-12-21 10:26:43
ding
回复人:flashasp(flashasp)2005-12-21 14:48:19
是不是每隔一段时间刷新一下,从服务器服数据,asp.net一般用webService方式上传和刷新聊天记录
发消息,调用远程webService 将消息存放临时变量或数据库,每隔一小段时间通过webService从服务器取还没有读过的聊天记录。
回复人:dandan(shuiziliu1982)2005-12-21 14:59:39
up
回复人:水手(yzh0523)2005-12-21 15:09:08
自己以前写过一个仿Web版的MSN,采用的是WebService+JS,通过JS定时调用WebService的方法,刷新聊天信息
回复人:flashasp(flashasp)2005-12-21 15:26:30
那么用户一多起来,服务器受地了吗?
回复人:电脑@锣钉(sysop_net)2005-12-22 14:34:59
up
回复人:小灰(http://blog.csdn.net/iuhxq)(iuhxq)2005-12-26 8:53:34
using System;
using System.Web;
using System.Collections;
namespace Chat
{
/// <summary>
/// Log &micro;&Auml;&Otilde;&ordf;&Ograve;&ordf;&Euml;&micro;&Atilde;÷&iexcl;&pound;
/// </summary>
public class Log
{
const int CacheLen = 5000;
public Log()
{
//
// TODO: &Ocirc;&Uacute;&acute;&Euml;&acute;&brvbar;&Igrave;í&frac14;&Oacute;&sup1;&sup1;&Ocirc;ì&ordm;&macr;&Ecirc;&yacute;&Acirc;&szlig;&frac14;&shy;
//
}
#region &Ecirc;&ocirc;&ETH;&Ocirc;
private int _ID;
public int ID
{
get
{
return _ID;
}
set
{
_ID = value;
}
}
private string _From;
public string From
{
get
{
return _From;
}
set
{
_From = value;
}
}
private string _FromName;
public string FromName
{
get
{
return _FromName;
}
set
{
_FromName = value;
}
}
private string _To;
public string To
{
get
{
return _To;
}
set
{
_To = value;
}
}
private string _ToName;
public string ToName
{
get
{
return _ToName;
}
set
{
_ToName = value;
}
}
private string _Content;
public string Content
{
get
{
return _Content;
}
set
{
_Content = value;
}
}
private DateTime _SendTime;
public DateTime SendTime
{
get
{
return _SendTime;
}
set
{
_SendTime = value;
}
}
#endregion
#region ·&frac12;·¨
/// <summary>
/// &sup2;&aring;&Egrave;&euml;&Aacute;&Auml;&Igrave;ì&frac14;&Ccedil;&Acirc;&frac14;
/// </summary>
/// <param name="action"></param>
/// <param name="content"></param>
public static void InsertLog(string action, string content)
{
string sid = HttpContext.Current.Session.SessionID;
MyUser user = MyUser.GetUser();
switch (action)
{
case "stop":
if (user.SID == sid)
{
InsertLog("", "stop");
MyUser.Stop();
}
return;
case "exit":
InsertLog("", "exit");
MyUser.Logout();
return;
case "login":
MyUser.Login(content);
InsertLog("", "login");
return;
}
content = HttpContext.Current.Server.HtmlEncode(content);
HttpContext.Current.Application.Lock();
ArrayList logs = (ArrayList)HttpContext.Current.Application["logs"];
int id = -1;
if(logs.Count>0)
{
id = ((Log)logs[logs.Count-1]).ID;
}
id++;

Log log = new Log();
log.ID = id;
log.From = sid;
log.To = (user.SID == sid)? user.ToSID : user.SID;
log.FromName = (user.SID == sid)? user.Name : user.ToName;
log.ToName = (user.SID == sid)? user.ToName : user.Name;
log.SendTime = DateTime.Now;
log.Content = content;
logs.Add(log);
if(logs.Count>CacheLen)
{
logs.RemoveRange(0, logs.Count-CacheLen);
}
HttpContext.Current.Application["logs"] = logs;
HttpContext.Current.Application.UnLock();
}
/// <summary>
/// &sup2;é&Ntilde;&macr;&Aacute;&Auml;&Igrave;ì&frac14;&Ccedil;&Acirc;&frac14;
/// </summary>
/// <param name="lid"></param>
/// <returns></returns>
public static ArrayList GetLog(int lid)
{
string sid = System.Web.HttpContext.Current.Session.SessionID;
MyUser user = MyUser.GetUser();
HttpContext.Current.Application.Lock();
ArrayList logs = (ArrayList)HttpContext.Current.Application["logs"];
HttpContext.Current.Application.UnLock();
if(logs.Count>0)
{
if(user == null || user.ToSID == sid)//&AElig;&Otilde;&Iacute;¨&Oacute;&Atilde;&raquo;§
{
ArrayList newlogs = new ArrayList();
for(int i = 0;i<logs.Count;i++)
{
if( ((Log)(logs[i])).ID > lid && (((Log)(logs[i])).From == sid || ((Log)(logs[i])).To == sid))
{
newlogs.Add((Log)logs[i]);
}
}
return newlogs;
}
else//&iquest;&Iacute;·&thorn;
{
for(int i = 0;i<logs.Count;i++)
{
if(((Log)logs[i]).ID>lid)
{
return logs.GetRange(i, logs.Count-i);
}
}
}
}
return null;
}
//public static void RemoveLog(string uid)
//{
//HttpContext.Current.Application.Lock();
//ArrayList logs = (ArrayList)HttpContext.Current.Application["logs"];
//for( int i=logs.Count-1; i>=0; i--)
//{
//if ( (((Log)logs[i]).From == uid || ((Log)logs[i]).To == uid) && ((Log)logs[i]).Type == 0 )
//{
//logs.RemoveAt(i);
//}
//}
//HttpContext.Current.Application["logs"] = logs;
//HttpContext.Current.Application.UnLock();
//}
#endregion
}
}
回复人:小灰(http://blog.csdn.net/iuhxq)(iuhxq)2005-12-26 8:54:55
<%@ Page language="c#" Codebehind="Admin.aspx.cs" AutoEventWireup="false" Inherits="Chat.Admin" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Admin</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<link href="style.css" rel="stylesheet" type="text/css">
</HEAD>
<body MS_POSITIONING="GridLayout" onunload="exit();">
<form id="Form1" method="post" runat="server">
<div align="left"></div>
<FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体">
</FONT><FONT face="宋体"></FONT>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="500" style="WIDTH: 585px"><div align="left"></div>
<table width="500" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td><img src="images/img01.gif" width="30" height="27" hspace="5" vspace="2"></td>
<td width="471" class="14font" style="WIDTH: 471px">您好,欢迎光临客服在线答疑!如果您有什么问题或是建议,请直接与我们的客服人员联系。
<a href="logout.aspx">退出</a>
<INPUT name="button" type="button" onclick="Send('stop','');" value="结束会话"><INPUT name="button" type="button" onclick="log.innerHTML='';" value="清屏">
<input type="button" value="保存记录" onclick="save.document.write(log.innerHTML);save.document.execCommand('SaveAs',true,'text.txt')">
<iframe name="save" style="display:none;"></iframe>
<select name="color">
<option value="red">红</option>
<option value="yellow">黄</option>
<option value="blue">蓝</option>
<option value="black">黑</option>
<option value="white">白</option>
</select>
</td>
</tr>
<tr>
<td height="23" colspan="2" class="14font" style="WIDTH: 572px"><FONT face="宋体"></FONT></td>
</tr>
<tr>
<td height="1" colspan="2" background="images/img07.gif" style="WIDTH: 572px"></td>
</tr>
<tr>
<td height="23" colspan="2" style="WIDTH: 500px"><div id="log" style="FONT-WEIGHT: normal; FONT-SIZE: 9pt; OVERFLOW: auto; WIDTH: 500px; WORD-BREAK: break-all; LINE-HEIGHT: normal; FONT-STYLE: normal; HEIGHT: 400px; FONT-VARIANT: normal"></div>
<FONT face="宋体"></FONT><FONT face="宋体"></FONT>
</td>
</tr>
<tr>
<td colspan="2" height="5" style="WIDTH: 572px"><input type="checkbox" id="me">只显示我的聊天内容
</td>
</tr>
<tr>
<td colspan="2" style="WIDTH: 572px"><INPUT name="text" type="text" id="content" onkeydown="if(event.keyCode==13){Send('',document.getElementById('content').value);return false;}"
size="70" maxlength="200"> <INPUT name="button" type="button" onclick="Send('',document.getElementById('content').value);" value="发送"></td>
</tr>
</table>
<div align="left"></div>
</td>
<td width="600"><iframe src="list.aspx" frameborder="0" scrolling="no" height="700px" width="100%"></iframe>
</td>
</tr>
</table>
<script language="javascript">
var lid = -1;
GetLog();
setInterval(GetLog, 5000);
function GetLog()
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load('GetLog.aspx?lid='+lid);
xmlObj=xmlDoc.documentElement;
nodes = xmlDoc.documentElement.childNodes;
for(i=0;i<nodes.length;i++)
{
var str = '';
if (document.all.me.checked && nodes[i].childNodes[1].text != sid && nodes[i].childNodes[3].text != sid)
{
lid = nodes[i].childNodes[0].text;
continue;
}
if (nodes[i].childNodes[1].text == sid)
{
str = "我 对 " + (nodes[i].childNodes[4].text==""? nodes[i].childNodes[3].text:nodes[i].childNodes[4].text) +" 说:<font color=" + document.all.color.value + ">" +nodes[i].childNodes[6].text+"</font>("+nodes[i].childNodes[5].text+")<br/>";
}
else if (nodes[i].childNodes[3].text == sid)
{
str = (nodes[i].childNodes[2].text==""? nodes[i].childNodes[1].text:nodes[i].childNodes[2].text)+" 对 我 说:<font color=" + document.all.color.value + ">" +nodes[i].childNodes[6].text+"</font>("+nodes[i].childNodes[5].text+")<br/>";
}
else
{
str = (nodes[i].childNodes[2].text==""? nodes[i].childNodes[1].text:nodes[i].childNodes[2].text)+" 对 " + (nodes[i].childNodes[4].text==""? nodes[i].childNodes[3].text:nodes[i].childNodes[4].text) +" 说:" +nodes[i].childNodes[6].text+"("+nodes[i].childNodes[5].text+")<br/>";
}
log.innerHTML += str;
lid = nodes[i].childNodes[0].text;
}
log.scrollTop = 9999;
}
function Send(action, content)
{
if(action.length<1 && content.length<1)
{
alert('请输入您的交谈内容');
return;
}
var Body = 'action='+action+'&content='+document.getElementById('content').value;
var xml = new ActiveXObject("Microsoft.XMLHTTP");
xml.open("POST",'chat.aspx',false);
xml.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
xml.setRequestHeader("Content-Length",escape(Body).length)
xml.send(Body);
document.getElementById('content').value = "";
}
function exit()
{
Send("exit", "");
}
</script>
</form>
</body>
</HTML>
回复人:小灰(http://blog.csdn.net/iuhxq)(iuhxq)2005-12-26 8:56:15
protected void Application_Start(Object sender, EventArgs e)
{
ArrayList users = new ArrayList();
Application["users"] = users;
ArrayList admins = new ArrayList();
Application["admins"] = admins;
ArrayList Logs = new ArrayList();
Application["logs"] = Logs;
}
<%@ Page language="c#" Codebehind="GetLog.aspx.cs" AutoEventWireup="false" Inherits="Chat.GetLog" %><?xml version="1.0" encoding="utf-8" ?>
<Log>
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate><item>
<id><%# DataBinder.Eval(Container.DataItem, "id")%></id>
<from><%# DataBinder.Eval(Container.DataItem, "from")%></from>
<fromname><%# DataBinder.Eval(Container.DataItem, "fromname")%></fromname>
<to><%# DataBinder.Eval(Container.DataItem, "to")%></to>
<toname><%# DataBinder.Eval(Container.DataItem, "toname")%></toname>
<SendTime><%# DataBinder.Eval(Container.DataItem, "SendTime")%></SendTime>
<content><%# DataBinder.Eval(Container.DataItem, "content")%></content>
</item></ItemTemplate>
</asp:Repeater>
</Log>

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Response.ContentType = "text/xml";
Response.Expires = -1;
Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
Response.CacheControl = "no-cache";

int lid = int.Parse(Request["lid"]);
Repeater1.DataSource = Log.GetLog(lid);
Repeater1.DataBind();
}
回复人:㊣快乐王子㊣(www_acafa_com)2005-12-26 8:58:44
我参与的问题.
回复人: ? (Study_Now)2005-12-26 8:59:37
up
回复人:寂寞成双.Net(benlee)2005-12-26 9:02:31
我知道整个实现过程