追寻人生

学习之园地,创意之源泉

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  33 随笔 :: 13 文章 :: 26 评论 :: 0 引用

2011年12月31日 #

我的Openfire群实现思路:

1、群和群成员,要保存到表中。

2、拉取群列表和群成员列表,均从DB中查询返回。

3、抛弃老外的“进房间,要发Presence ”。只要此人一上线,就模似一个Presence进行joinRoom,进入他的各群房间。

     多了解LocalMUCRoom 类中:public LocalMUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest, LocalMUCUser user, Presence presence)

    我的模似代码如下:

View Code
 1 /**
 2      * 模似用户进群(含呢称、含Precense、初始化角色LocalMUCRole)
 3      * @param roomId
 4      * @param packet
 5      * @return
 6      */
 7     public MUCRole getRolesByRoomId(long roomId, Packet packet)
 8     {
 9         MUCRole role = null;
10         try {
11             // Get or create the room  获取该群
12             MUCRoom room = server.getChatRoom(roomId, packet.getFrom());
13             
14             //从数据库中查询他的姓名作为昵称(得自己实现)
15             String nickname = new MUCRoomServiceDao().getUserNickname(packet.getFrom().getNode());
16             if(nickname == null)
17             {
18                 if(packet.getFrom().getResource() != null)
19                 {
20                     nickname = packet.getFrom().getResource();
21                 }
22                 else 
23                 {
24                     nickname = packet.getFrom().getNode();
25                 }
26             }
27             
28             HistoryRequest historyRequest = null;
29             String password = null;
30             
31             //构建成员进入群的Presence
32             Presence presence = new Presence();
33             presence.setTo(room.getJID().toBareJID() + "/" + nickname);    
34             presence.setFrom(packet.getFrom());
35             PacketExtension extension = new PacketExtension("x", http://jabber.org/protocol/muc);
36             presence.addExtension(extension);
37             
38             // The user joins the room 用户进入群
39             role = room.joinRoom(nickname,
40                     password,
41                     historyRequest,
42                     this,
43                     presence);
44             
45             // If the client that created the room is non-MUC compliant then
46             // unlock the room thus creating an "instant" room
47             //if (mucInfo == null && room.isLocked() && !room.isManuallyLocked()) {
48             if (room.isLocked() && !room.isManuallyLocked()) {
49                 room.unlock(role);
50                 //server.chatRoomAdded((LocalMUCRoom)room);
51             }
52             
53             addRole(roomId, (LocalMUCRole)role);//添加“用户在某个群中的角色”
54             
55         }
56         catch (UnauthorizedException e) {
57             sendErrorPacket(packet, PacketError.Condition.not_authorized);
58         }
59         catch (ServiceUnavailableException e) {
60             sendErrorPacket(packet, PacketError.Condition.service_unavailable);
61         }
62         catch (UserAlreadyExistsException e) {
63             sendErrorPacket(packet, PacketError.Condition.conflict);
64         }
65         catch (RoomLockedException e) {
66             sendErrorPacket(packet, PacketError.Condition.recipient_unavailable);
67         }
68         catch (ForbiddenException e) {
69             sendErrorPacket(packet, PacketError.Condition.forbidden);
70         }
71         catch (RegistrationRequiredException e) {
72             sendErrorPacket(packet, PacketError.Condition.registration_required);
73         }
74         catch (ConflictException e) {
75             sendErrorPacket(packet, PacketError.Condition.conflict);
76         }
77         catch (NotAcceptableException e) {
78             sendErrorPacket(packet, PacketError.Condition.not_acceptable);
79         }
80         catch (NotAllowedException e) {
81             sendErrorPacket(packet, PacketError.Condition.not_allowed);
82         }        
83         return role;
84     }

 4、抛弃老外的“以昵称为Key 缓存群成员”。改为以帐号为Key。

     多了解 LocalMUCRoom 类中:private Map<String,MUCRole> occupants = new ConcurrentHashMap<String, MUCRole>();

     在joinRoom办法中:    

View Code
1 //以JID作为缓存的key
2         JID userJid = user.getAddress();
3         if (userJid != null) {
4             occupants.put(userJid.toBareJID(), joinRole);
5         }

 5、详细了解 LocalMUCRoom、LocalMUCUser、LocalMUCRole这三个类,各类中的数据成员、方法。 

 

posted @ 2011-12-31 17:53 追梦华仔 阅读(80) 评论(1) 编辑

2011年12月21日 #

1、各Openfire服务器得设置不同的域名,即 ofProperty表xmpp.domain属性,如设置 192.168.1.46等。

2、Dialback提供一种弱身份验证的方式,要使用这种方式可以将 ofproperty表中“xmpp.server.tls.enabled” 设置为false,并将“xmpp.server.dialback.enabled”设置为true。

3、Socket探测对方5269端口是否开放。

LocalOutgoingServerSession类 createOutgoingSession方法:

View Code
 1 private static LocalOutgoingServerSession createOutgoingSession(String domain, String hostname,
 2             int port) {
 3         boolean useTLS = JiveGlobals.getBooleanProperty("xmpp.server.tls.enabled", true);
 4         RemoteServerConfiguration configuration = RemoteServerManager.getConfiguration(hostname);
 5         if (configuration != null) {
 6             // TODO Use the specific TLS configuration for this remote server
 7             //useTLS = configuration.isTLSEnabled();
 8         }
 9 
10         // Connect to remote server using XMPP 1.0 (TLS + SASL EXTERNAL or TLS + server dialback or server dialback)
11         SocketConnection connection = null;
12         String realHostname = null;
13         int realPort = port;
14         Socket socket = new Socket();
15         try {
16             // Get the real hostname to connect to using DNS lookup of the specified hostname
17             DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname, port);
18             realHostname = address.getHost();
19             realPort = address.getPort();
20             Log.debug("LocalOutgoingServerSession: OS - Trying to connect to " + hostname + ":" + port +
21                     "(DNS lookup: " + realHostname + ":" + realPort + ")");
22             // Establish a TCP connection to the Receiving Server
23             socket.connect(new InetSocketAddress(realHostname, realPort),
24                     RemoteServerManager.getSocketTimeout());
25             Log.debug("LocalOutgoingServerSession: OS - Plain connection to " + hostname + ":" + port + " successful");
26         }
27         catch (Exception e) {
28             Log.error("Error trying to connect to remote server: " + hostname +
29                     "(DNS lookup: " + realHostname + ":" + realPort + ")", e);
30             return null;
31         }

 

4、握手。
LocalOutgoingServerSession类 createOutgoingSession方法:

View Code
 1 // Check if we are going to try server dialback (XMPP 1.0)
 2                     else if (ServerDialback.isEnabled() && features.element("dialback") != null) {
 3                         Log.debug("LocalOutgoingServerSession: OS - About to try connecting using server dialback XMPP 1.0 with: " + hostname);
 4                         ServerDialback method = new ServerDialback(connection, domain);
 5                         OutgoingServerSocketReader newSocketReader = new OutgoingServerSocketReader(reader);                        
 6                         if (method.authenticateDomain(newSocketReader, domain, hostname, id)) {
 7                             Log.debug("LocalOutgoingServerSession: OS - SERVER DIALBACK XMPP 1.0 with " + hostname + " was successful");                            
 8                             StreamID streamID = new BasicStreamIDFactory().createStreamID(id);
 9                             LocalOutgoingServerSession session = new LocalOutgoingServerSession(domain, connection, newSocketReader, streamID);
10                             connection.init(session);
11                             // Set the hostname as the address of the session
12                             session.setAddress(new JID(null, hostname, null));                            
13                             return session;
14                         }
15                         else {
16                             Log.debug("LocalOutgoingServerSession: OS - Error, SERVER DIALBACK with " + hostname + " failed");
17                         }
18                     }
19                     

 

5、建立信任。加入路由表的serversCache缓存。
RoutingTableImpl类 routePacket(JID jid, Packet packet, boolean fromServer)方法:

View Code
 1 // Packet sent to remote server
 2             byte[] nodeID = serversCache.get(jid.getDomain());
 3             if (nodeID != null) {
 4                 if (server.getNodeID().equals(nodeID)) {
 5                     // This is a route to a remote server connected from this node
 6                     try {
 7                         localRoutingTable.getRoute(jid.getDomain()).process(packet);
 8                         routed = true;
 9                     } catch (UnauthorizedException e) {
10                         Log.error(e);
11                     }
12                 }
13                 else {
14                     // This is a route to a remote server connected from other node
15                     if (remotePacketRouter != null) {
16                         routed = remotePacketRouter.routePacket(nodeID, jid, packet);
17                     }
18                 }
19             }
20             else {
21                 // Return a promise of a remote session. This object will queue packets pending
22                 // to be sent to remote servers
23                 OutgoingSessionPromise.getInstance().process(packet);
24                 routed = true;
25             }

 

6、包再次路由,通过SocketConnection类的deliver(Packet packet)发出。

View Code
 1 public void deliver(Packet packet) throws UnauthorizedException, PacketException {
 2         if (isClosed()) {
 3             backupDeliverer.deliver(packet);
 4         }
 5         else {
 6             boolean errorDelivering = false;
 7             boolean allowedToWrite = false;
 8             try {
 9                 requestWriting();
10                 allowedToWrite = true;
11                 xmlSerializer.write(packet.getElement());
12                 if (flashClient) {
13                     writer.write('\0');
14                 }
15                 xmlSerializer.flush();
16             }
17             catch (Exception e) {
18                 Log.debug("Error delivering packet" + "\n" + this.toString(), e);
19                 errorDelivering = true;
20             }
21             finally {
22                 if (allowedToWrite) {
23                     releaseWriting();
24                 }
25             }
26             if (errorDelivering) {
27                 close();
28                 // Retry sending the packet again. Most probably if the packet is a
29                 // Message it will be stored offline
30                 backupDeliverer.deliver(packet);
31             }
32             else {
33                 session.incrementServerPacketCount();
34             }
35         }
36     }

  

7、对方Openfire服务器在ServerSocketReader类的 packetReceived(Packet packet) 接收,并响应回包。

View Code
 1 private void packetReceived(Packet packet) throws PacketRejectedException {
 2         if (packet.getTo() == null || packet.getFrom() == null) {
 3             Log.debug("Closing IncomingServerSession due to packet with no TO or FROM: " +
 4                     packet.toXML());
 5             // Send a stream error saying that the packet includes no TO or FROM
 6             StreamError error = new StreamError(StreamError.Condition.improper_addressing);
 7             connection.deliverRawText(error.toXML());
 8             // Close the underlying connection
 9             connection.close();
10             open = false;
11             throw new PacketRejectedException("Packet with no TO or FROM attributes");
12         }
13         else if (!((LocalIncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) {
14             Log.debug("Closing IncomingServerSession due to packet with invalid domain: " +
15                     packet.toXML());
16             // Send a stream error saying that the packet includes an invalid FROM
17             StreamError error = new StreamError(StreamError.Condition.invalid_from);
18             connection.deliverRawText(error.toXML());
19             // Close the underlying connection
20             connection.close();
21             open = false;
22             throw new PacketRejectedException("Packet with no TO or FROM attributes");
23         }
24     }

 

posted @ 2011-12-21 12:21 追梦华仔 阅读(88) 评论(0) 编辑

2008年1月8日 #

1、在命令行下执行:
    cmd
    regsvr32 jmail.dll

2、在安装程序中:
 public override void Install(System.Collections.IDictionary stateSaver)
  { 
   base.Install(stateSaver);
   try
   {
    /*
    在制作安装包时,自定义操作->安装,添加自定义操作(来自XX安装程序的主输出),配置
CustomerActionData=/targetdir="[TARGETDIR]\"
    */  

    string targetdir=this.Context.Parameters["targetdir"].Trim();
    if(!targetdir.EndsWith(@"\"))
        targetdir+=@"\";
   
   //注册Jmail组件
    try
    {
     JmailReg(targetdir);
    }
    catch(Exception)
    { }
    
   }
   catch(Exception ex)
   {
    throw ex;
   }
 }

3、在Windows应用程序中:
private void DoUpdate()
  {
   string strPath=Application.StartupPath;
   IniFile ini = new IniFile(strPath+@"\sys.ini");
   //注册Jmail
   if(ini.IniReadValue("System","JmailReg").ToString()!="1")
   {
    JmailReg(strPath);
    ini.IniWriteValue("System","JmailReg","1");
   }
 }

private void JmailReg(string targetdir)
  {
   try
   {
    ProcessStartInfo processInfo =new ProcessStartInfo("regsvr32");
    //processInfo.WindowStyle=ProcessWindowStyle.Normal;
    
processInfo.WindowStyle=ProcessWindowStyle.Hidden;
    processInfo.Arguments=" /s "+ Char.ToString('"') + targetdir + "jmail.dll"+Char.ToString('"');      
    Process osql = Process.Start(processInfo);
    //Wait till it is done...
    osql.WaitForExit();
    osql.Dispose();
    processInfo=null;
   }
   catch(Exception)
   {}
  }

posted @ 2008-01-08 10:51 追梦华仔 阅读(2241) 评论(1) 编辑

2007年12月7日 #

OleDbConnection myOleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(filepath)+";Extended Properties='Excel 8.0;IMEX=1'"); 
OleDbDataAdapter myOledbDataAdapter = new OleDbDataAdapter("SELECT * FROM [student$]",myOleDbConnection);
DataSet ds = new DataSet();
myOledbDataAdapter.Fill(ds);

当程序运作到此处时,会提示“外部表不是预期的格式”的错误。


解决方法:
    用记事本打开你的excel文件,看看显示是否为乱码。
    若是html代码,则表示你的excel文件格式不是标准的excel格式,才会提示“外部表不是预期的格式”的错误;
    若是乱码,我这边测试是不会提示这个错误的,可以成功导入。

posted @ 2007-12-07 11:36 追梦华仔 阅读(8368) 评论(6) 编辑

2007年12月6日 #

 

“/”应用程序中的服务器错误。

服务器出现意外情况。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Runtime.InteropServices.COMException: 服务器出现意外情况。

源错误:

行 164:					//Excel工作表
            行 165:					Excel.Workbook theWorkbook;
            行 166:					theWorkbook =
            行 167:						ExcelObj.Workbooks.Open(
            行 168:						filepath, 0, true, 5,

源文件: d:\sites\monitorcheck\web\systemmng\import.aspx.cs    行: 166

堆栈跟踪:

[COMException (0x80010105): 服务器出现意外情况。]
            Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru) +0
            Web.SystemMng.Import.ReadExcel(String strPPath, String filename, String UserName) in d:\sites\monitorcheck\web\systemmng\import.aspx.cs:166
            Web.SystemMng.Import.btnConfirm_Click(Object sender, EventArgs e) in d:\sites\monitorcheck\web\systemmng\import.aspx.cs:105
            System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
            System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
            System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
            System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
            System.Web.UI.Page.ProcessRequestMain() +1292
            


版本信息: Microsoft .NET Framework 版本:1.1.4322.2407; ASP.NET 版本:1.1.4322.2407


我照着网友提供的解决方法“配置Dcom。运行Dcomcnfg.exe,找到Excel应用程序,配置其属性,身份验证级别选无,身份标识选"交互式用户",安全性页面,启动和访问均给everyone。
还是不行呀!!!

我现在附上我设置的图片,让高手帮我指点一下,看哪里设置有错??



posted @ 2007-12-06 18:34 追梦华仔 阅读(3693) 评论(1) 编辑

 

“/”应用程序中的服务器错误。

拒绝访问。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.UnauthorizedAccessException: 拒绝访问。

ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}\ASPNET,在 IIS 6 上为网络服务)。如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。

若要授予 ASP.NET 对文件的写访问权,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。

源错误:

行 156:					//Excel对象
            行 157:					Excel.Application ExcelObj = null;
            行 158:					ExcelObj =  new Excel.Application();
            行 159:					if (ExcelObj  == null)
            行 160:					{

源文件: d:\sites\monitorcheck\web\systemmng\import.aspx.cs    行: 158

堆栈跟踪:

[UnauthorizedAccessException: 拒绝访问。]
            Web.SystemMng.Import.ReadExcel(String strPPath, String filename, String UserName) in d:\sites\monitorcheck\web\systemmng\import.aspx.cs:158
            Web.SystemMng.Import.btnConfirm_Click(Object sender, EventArgs e) in d:\sites\monitorcheck\web\systemmng\import.aspx.cs:105
            System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
            System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
            System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
            System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
            System.Web.UI.Page.ProcessRequestMain() +1292
            


版本信息: Microsoft .NET Framework 版本:1.1.4322.2407; ASP.NET 版本:1.1.4322.2407




我设了  ASP.NET 帐户的访问权限,为完全控制,  也还是一样出错。

请教高手指点一下。



posted @ 2007-12-06 17:39 追梦华仔 阅读(663) 评论(1) 编辑

2007年11月5日 #

摘要: 在 ASP.NET 中执行 URL 重写 http://msdn2.microsoft.com/zh-cn/library/ms972974.aspx阅读全文
posted @ 2007-11-05 00:21 追梦华仔 阅读(100) 评论(0) 编辑

2007年9月25日 #

摘要: 转载于 http://topic.csdn.net/t/20050728/02/4172764.html"我的系统一旦遇到要访问文件的时候就会出错,其中一个具体信息如下: 对路径 'F:\bbs\skyBoard\Config\siteConst.config' 的访问被拒绝。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的...阅读全文
posted @ 2007-09-25 19:10 追梦华仔 阅读(1455) 评论(0) 编辑

摘要: 一般用下面的方法可以解决:1:确认在“配置属性”中的“启用ASP.NET调试"为"True"2:确认你的"web.config"中的"debug=true"3:若你安装过Win2000SP4后,则要在命令行执行"regsvr32iaspnet_isap.dll"4:在IIS里查看站点信息,选中"目录安全性",里面有"匿名访问和身份验证控制",再点击"编辑..",...阅读全文
posted @ 2007-09-25 18:38 追梦华仔 阅读(261) 评论(0) 编辑

2007年9月9日 #

摘要: 创建asp.net网站时出现问题,访问aspx网页时出现 http 500内部服务器错误,历经波折,终于将其搞定,描述如下:1. internet选项--高级,去除“显示友好 http 错误信息”前面的钩2. 再次访问aspx网页时 ,显示Server Application Error3. 查看系统日志 事件类型:警告 事件来源:W3SVC 事件 ID:36 描述: 服务...阅读全文
posted @ 2007-09-09 15:49 追梦华仔 阅读(746) 评论(0) 编辑