- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 Amazon 上托管了 Ejabberd
聊天服务器并在那里添加了两个用户,当我尝试通过 Adium
连接 Ejabberd 服务器时,它要求证书然后才连接,现在我正在使用 Ejabberd 服务器和 XMPP 在 Swift
中开发聊天应用程序,我配置了所有代码,传递了主机名和端口号:5222,但它没有连接到服务器。我是否需要编写程序来获取服务器证书并将我的计算机证书 (.p12) 文件传递给服务器?
注意:我在本地主机中配置了 Ejabberd 服务器并通过 iOS Swift 代码,当我从 iOS 应用程序发送消息然后它显示在 Adium 中并且当 Adium 用户发送消息然后我转到 Ejabberd 时它工作完美Web 管理面板,可以查看离线消息。
以下是 Swift 中用于连接在 Amazon 上托管的 Ejabberd 的代码:
//
// AppDelegate.swift
// Thanks to Process One for this.
import UIKit
import XMPPFramework
protocol ChatDelegate {
func buddyWentOnline(_ name: String)
func buddyWentOffline(_ name: String)
func didDisconnect()
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, XMPPRosterDelegate, XMPPStreamDelegate {
var window: UIWindow?
var delegate:ChatDelegate! = nil
let xmppStream = XMPPStream()
let xmppRosterStorage = XMPPRosterCoreDataStorage()
var xmppRoster: XMPPRoster
override init() {
xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
DDLog.add(DDTTYLogger.sharedInstance())
setupStream()
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
disconnect()
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
connect()
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
//MARK: Private Methods
func setupStream() {//fileprivate
//xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)
xmppRoster.activate(xmppStream)
xmppStream?.addDelegate(self, delegateQueue: DispatchQueue.main)
xmppRoster.addDelegate(self, delegateQueue: DispatchQueue.main)
}
func goOnline() { //fileprivate
let presence = XMPPPresence()
let domain = xmppStream?.myJID.domain
if domain == "gmail.com" || domain == "gtalk.com" || domain == "talk.google.com" {
let priority = DDXMLElement.element(withName: "priority", stringValue: "24") as! DDXMLElement
presence?.addChild(priority)
}
xmppStream?.send(presence)
}
func goOffline() { //fileprivate
let presence = XMPPPresence(type: "unavailable")
xmppStream?.send(presence)
}
func connect() -> Bool {
xmppStream.hostName = "amazon hosted ejabber ip address"
xmppStream.hostPort=5222
if !(xmppStream?.isConnected())! {
let jabberID = UserDefaults.standard.string(forKey: "userID")
let myPassword = UserDefaults.standard.string(forKey: "userPassword")
if !(xmppStream?.isDisconnected())! {
return true
}
if jabberID == nil && myPassword == nil {
return false
}
xmppStream?.myJID = XMPPJID.init(string: jabberID)
do {
try xmppStream?.connect(withTimeout: XMPPStreamTimeoutNone)
print("Connection success")
return true
} catch {
print("Something went wrong!")
return false
}
} else {
return true
}
}
func disconnect() {
goOffline()
xmppStream?.disconnect()
}
//MARK: XMPP Delegates
func xmppStreamDidConnect(_ sender: XMPPStream!) {
do {
try xmppStream?.authenticate(withPassword: UserDefaults.standard.string(forKey: "userPassword"))
} catch {
print("Could not authenticate")
}
}
func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
goOnline()
}
func xmppStream(_ sender: XMPPStream!, didReceive iq: XMPPIQ!) -> Bool {
print("Did receive IQ")
return false
}
func xmppStream(_ sender: XMPPStream!, didReceive message: XMPPMessage!) {
print("Did receive message \(message)")
}
func xmppStream(_ sender: XMPPStream!, didSend message: XMPPMessage!) {
print("Did send message \(message)")
}
func xmppStream(_ sender: XMPPStream!, didReceive presence: XMPPPresence!) {
let presenceType = presence.type()
let myUsername = sender.myJID.user
let presenceFromUser = presence.from().user
if presenceFromUser != myUsername {
print("Did receive presence from \(presenceFromUser)")
if presenceType == "available" {
delegate.buddyWentOnline("\(presenceFromUser)@gmail.com")
} else if presenceType == "unavailable" {
delegate.buddyWentOffline("\(presenceFromUser)@gmail.com")
}
}
}
func xmppRoster(_ sender: XMPPRoster!, didReceiveRosterItem item: DDXMLElement!) {
print("Did receive Roster item")
}
}
最佳答案
最后我设法解决了这个问题,我真的很惊讶能够使用托管在亚马逊上的 Ejabberd 服务器实现聊天应用程序。
问题:
1.当我运行我的应用程序时,它没有连接?
答案:证书问题(服务器-客户端证书握手解决问题)
2. 无法获取在线好友?回答:我使用 Adium 让所有用户都在线,然后运行我的应用程序,它非常有效。
这个应用程序对我来说是很好的学习。如果任何人对聊天有任何问题,请随时发表评论,我期待着帮助。谢谢
关于ios - 将 iOS 应用程序连接到亚马逊上托管的 Ejabberd 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41743377/
我们正在使用 ejabberd_16.01-0_amd64.deb,我们希望将每个房间的最大用户数设置为 10000。根据文档:( https://docs.ejabberd.im/admin/con
我正在安装 ejabberd,但是当我使用 ./start 命令通过终端运行它时。它给出了 ejabberd 节点 ejabberd@localhost 已经运行的错误。 我已经卸载了 ejabber
我需要在 ejabberd 中存储每个用户的数据。我该怎么做?我的意思是我需要向用户表添加一个字段,并且我应该随时更新此数据。 我该怎么做? 最佳答案 这就是我正在做的事情。 在我的 Android
我是 ejabberd 的新手,我编译并运行了服务器,但在启动过程中出现此错误。该日志不是很有帮助,但也许有人比我更知道如何解析它。任何见解都会很棒。 =CRASH REPORT==== 17
我试图在 ejabberd 上启动 BOSH。我的 ejabberd.cfg 片段如下: {5280, ejabberd_http, [ {reques
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我正在按照本指南将 Ejabberd 嵌入到 Phoenix 应用程序 ( https://blog.process-one.net/embedding-ejabberd-into-an-elixir
我对 ejabberd 完全陌生。我已经下载了 Windows 和 Linux (Ubuntu) 的安装程序。我在网上的某个地方看到了如何安装和设置它的演示,但安装被配置为“演示”。我有 pidgin
按照 https://github.com/processone/ejabberd-contrib 中的说明进行操作我尝试运行: ejabberdctl module_install ejabberd
我想在 ejabberd 中配置 STUN/TURN,以便将 WebRTC 与“对话”XMPP 客户端一起使用。 我当然看了ejabberd STUN/TURN documentation以及如何操作
我在 Windows 中安装了 ejabberd。我在ejabberd文档查了半天,查了ejabberd安装文件夹(我电脑C:\Program Files\ejabberd-15.09),没找到文件e
我尝试将 Jitsi 与 ejabberd 连接,但在服务器运行并成功连接到 Pidgin 客户端时出现错误“未连接到服务器”。有人可以帮忙吗? 最佳答案 尝试在帐户配置文件中编辑连接设置: 连接服务
您好,我已经在我的服务器上安装了 ejabberd 16.04.43,它可以根据我的需要运行。 现在我有了新的要求,要阻止特定用户访问特定用户 让我考虑几个用户: kandan cash mani k
我想访问 ejabberd 服务器的 Mnesia 数据库,但我不知道如何读取、写入和更新数据,有没有办法可以做到这一点。 我可以将数据库更改为 MySQL 而不是 Mnesia。 我试过这个 {od
我正在尝试通过 docker 设置 ejabberd 服务器,以便我可以使用 pidgin 与我的队友聊天。 我有以下 docker compose 文件: version: "2" services
我想使用自定义 tsung 节(测试 ejabberd)。 假设我的看起来像这样: 我如何将其添加到 tsung 配置中,例如:
我正在开发这个 JavaScript 聊天应用程序,一切正常,除了我想为新(网站访问者)用户分配昵称时。 我只是想知道是否有一种方法可以通过 ejabberd XML 请求或 ejabberdctl“
我按照文档查看了多个链接以了解如何在 ejabberd 服务器上上传文件,但仍然无法在 ejabberd 服务器上上传文件。我的动机是在尝试使用 postman 之前从 android 应用程序上传文
ejabberd版本:16.04 操作系统:CentOS 7 我按照本文档设置 xmlrpc 支持,并需要一些帮助来配置访问控制: https://www.ejabberd.im/ejabberd_x
我刚刚在 mac os 中安装了 EJabberd 14.07。我是 EJabberd 的新手,我想学习基础知识,例如如何创建 Hello World 示例、项目的结构是什么、如何编译和运行 EJab
我是一名优秀的程序员,十分优秀!