rails for openfire: xmpp4r使用实践
来源:互联网 发布:怎么看金十数据k 编辑:程序博客网 时间:2024/05/21 08:12
xmpp4r实现了xmpp协议,使rails与openfire通信成为可能。废话不多少,看代码吧。
- 安装xmpp4r
gem install xmpp4r
- code
# -*- encoding : utf-8 -*-#该程序主要是向openfire发送信息#用户已经在openfire注册了,测试帐号是:tester001,密码是123456#接受信息帐号:tester002,密码: 123456#openfire帐号已经启动了require 'xmpp4r/client'include JabberJabber::debug = true # 开启jabber的debug模式#----------------------------用户登录---------------------------------server_str = 'tester001@192.168.1.126/testing' #用户名@服务器地址/资源号(资源号可以任意设定)jid = JID::new(server_str)password = '123456'cl = Client::new(jid)cl.connectcl.auth(password)#----------------------------发送简单的消息-------------------------------to = "tester002@192.168.1.126/testing"subject = "测试xmpp4r,发送消息"body = "此处是消息的主题部分,应该可以看到很多字哦。"m = Message::new(to, body).set_type(:normal).set_id('1').set_subject(subject)cl.send m
openfire的安装,启动和配置请参考:http://blog.csdn.net/hexudong08/article/details/7369435
***如果spark想受到信息,必须以debug模式启动才行 - 参考文档
http://devblog.famundo.com/articles/2006/10/14/ruby-and-xmpp-jabber-part-2-logging-in-and-sending-simple-messages
http://devblog.famundo.com/articles/2006/10/18/ruby-and-xmpp-jabber-part-3-adding-html-to-the-messages
github source: https://github.com/ln/xmpp4r - 补充
用户注册server_str = "xxxxxxx@#{ip_addr}/testing" #用户名@服务器地址/资源号(资源号可以任意设定)jid = JID::new(server_str)password = '123456'cl = Client::new(jid)cl.connectfields = { "username" => "xxxxdxxx", "name" => "liuling", "password" => "123456"}cl.register(password, fields)
- rails for openfire: xmpp4r使用实践
- Ruby for Rails 实践1
- Ruby for Rails 实践2
- 使用 Rails 构建 API 实践
- Ruby for Rails 最佳实践Ⅰ
- Ruby for Rails 最佳实践Ⅱ
- Ruby for Rails 最佳实践Ⅲ
- Ruby for Rails 最佳实践Ⅳ
- Ruby for Rails 最佳实践Ⅴ
- Ruby for Rails 最佳实践Ⅵ
- Ruby for Rails 最佳实践Ⅶ
- Ruby for Rails 最佳实践Ⅷ
- Ruby for Rails 最佳实践Ⅸ
- Ruby for Rails 最佳实践Ⅹ
- Ruby for Rails 最佳实践Ⅺ
- Ruby for Rails 最佳实践Ⅻ
- Ruby for Rails 最佳实践ⅩⅢ
- Ruby for Rails 最佳实践ⅩⅣ
- (译)在cocos2d里面如何使用Texture Packer和像素格式来优化spritesheet
- 理性
- 修改文件上传大小限制
- love oneself
- try{} catch(…)
- rails for openfire: xmpp4r使用实践
- Android 全局变量
- 一次只做一件事
- 家的温暖
- 在windows下用虚拟机搭建 linux开发环境
- 一封绝妙的情书 An Ingenious Love Letter
- 使用SurfaceView 播放视频
- socket 编程
- git笔记