简体   繁体   English

应用中的iOS消息传递系统(聊天系统)

[英]iOS messaging system (chat system) in app

So I have my iOS App (it's a social networking one) and I would like to add a messaging and chat system. 所以我有我的iOS应用(这是一个社交网络应用),我想添加一个消息传递和聊天系统。 I've looked up ways to do this but haven't found one that I could either fully understand or implement as most were too complicated for what I want. 我已经找到了执行此操作的方法,但是还没有找到我可以完全理解或实现的方法,因为大多数操作对于我想要的而言太复杂了。

I have a "friend list" view controller and when touched in one of the names in the list , a "messages" view controller (just like any im window) goes in where you can chat with the selected friend. 我有一个“朋友列表”视图控制器,当触摸列表中的一个名称时,“消息”视图控制器(就像任何即时消息窗口一样)进入您可以与所选朋友聊天的位置。

The ways I found to do this were either XMPP or "a TCP connection". 我发现执行此操作的方法是XMPP或“ TCP连接”。 I tried understanding XMPP but for XMPP you need "logging in" etc, and that would require an extra id or something which would complicate things. 我试图了解XMPP,但是对于XMPP,您需要“登录”等,这将需要一个额外的ID或会使情况变得复杂的东西。 I already have my in app users ID – I don't want a second one just for chat. 我已经有我的应用内用户ID –我不想再有一个ID用于聊天。

The second method – making a TCP connection and sending messages via that connection – I could not fully understand nor find examples of it implemented. 第二种方法-建立TCP连接并通过该连接发送消息-我无法完全理解也找不到实现它的示例。

The most difficult part of a simple chat protocol is a fast way to notify the client that a message has been received. 简单聊天协议最困难的部分是通知客户端已收到消息的快速方法。 To do this with REST or HTTP for example requires the client poll the server every few seconds, which is inefficient and impractical if your app needs to scale. 例如,要使用REST或HTTP进行此操作,则要求客户端每隔几秒钟轮询一次服务器,如果您的应用需要扩展,则这种效率低下且不切实际。

XMPP certainly adds extra work. XMPP当然会增加额外的工作。 Your client will need to make a separate connection to the XMPP server, and you'll have to find a way to integrate authentication. 您的客户端将需要与XMPP服务器建立单独的连接,并且您将必须找到一种集成身份验证的方法。 But as long as the client has a connection open, it'll be notified the moment a message arrives. 但是只要客户端打开连接,消息到达时就会收到通知。

While chat isn't the same as publish–subscribe, they share the same design challenge, which is how to notify the client when a message is received without the client having to poll. 尽管聊天与发布-订阅不同,但是它们面临着相同的设计挑战,那就是如何在接收到消息时通知客户端而不必轮询客户端。 While researching choices for a publish–subscribe application I came upon a helpful chart comparing XMPP, RSS, and other options. 在研究发布-订阅应用程序的选择时,我遇到了一个比较XMPP,RSS和其他选项的有用图表 The same site offers a good explanation of polling . 同一站点对轮询也有很好的解释。 Again, it's not about chat, but you can still use it to understand the problem. 同样,它与聊天无关,但是您仍然可以使用它来了解问题。

As you mention, another option a TCP connection which is kept alive, on which the server can place responses when they arrive. 如您所述,另一个选择是保持活动的TCP连接,服务器可以在响应到达时在其上放置响应。 You can even do that over HTTP if you want. 如果需要,您甚至可以通过HTTP进行操作。 I'm not aware of any servers which do this right out of the box. 我不知道有任何开箱即用的服务器。 (For my needs I selected XMPP and XMPPFramework .) (出于我的需要,我选择了XMPP和XMPPFramework 。)

You can check out this link in which XAMPP framework is used... 您可以查看使用XAMPP框架的此链接...

https://github.com/KanybekMomukeyev/FacebookChat https://github.com/KanybekMomukeyev/FacebookChat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM