简体   繁体   English

与 iPhone 进行点对点聊天

[英]Peer-to-peer chat with the iPhone

I am aware of how many times this has been asked based on searching StackOverflow, but I am still hoping someone could tell me whether I am wrong...我知道根据搜索 StackOverflow 已经问了多少次这个问题,但我仍然希望有人能告诉我我是否错了......

I am creating a peer-to-peer chat app for the iPhone.我正在为 iPhone 创建一个点对点聊天应用程序。 My initial idea was to avoid using a server, so Bonjour came to mind.我最初的想法是避免使用服务器,所以我想到了 Bonjour。 I was happy coding for quite a while and implemented a lot of fancy features, but two days ago I started testing with two clients from different subnets and found that the clients couldn't connect to each other.有一段时间我很高兴编码并实现了许多花哨的功能,但是两天前我开始使用来自不同子网的两个客户端进行测试,发现客户端无法相互连接。 I suddenly realized that Bonjour is meant for local networks and that a DNS server is necessary for wide area service broadcasting?我突然意识到 Bonjour 是为本地网络设计的,而广域服务广播需要 DNS 服务器? Do I really need a server for Internet peer-to-peer chat?我真的需要一台服务器来进行 Internet 点对点聊天吗? Are there any other options that do not involve using a server on the iOS platform?是否还有其他不涉及在 iOS 平台上使用服务器的选项?

To answer the question, the only way is for you to carry a list of all possible participants, and their current IP address, and for each possible participant to report to all others each time their IP Address changes.要回答这个问题,唯一的方法是让您携带所有可能参与者的列表,以及他们当前的 IP 地址,并且每个可能的参与者在每次 IP 地址更改时向所有其他人报告。 So, if you have 100 possible participants, then you must tell 99 others when your IP Address changes, and those 99 must tell you when their IP Address changes.因此,如果您有 100 位可能的参与者,那么您必须在您的 IP 地址更改时告诉其他 99 人,而这 99 个人必须在他们的 IP 地址更改时告诉您。

Bonjour may work on a LAN, a WAN or even a WAN, but it will never work on the internet. Bonjour 可以在 LAN、WAN 甚至 WAN 上工作,但它永远不会在 Internet 上工作。

The role of the server is so that each end point only need to tell one end point (the server) when it changes.服务器的作用是让每个端点在发生变化时只需要告诉一个端点(服务器)。 My advice is get a cheap internet host, with a basic PHP / MySQL capabilities, and write yourself a very simple script to post and get user identities.我的建议是买一个便宜的互联网主机,具有基本的 PHP / MySQL 功能,并为自己编写一个非常简单的脚本来发布和获取用户身份。

I am wondering how you can do a chat app without using a server.我想知道如何在不使用服务器的情况下制作聊天应用程序。 There are many cheap solutions out there, Amazon has its own service, Google does as well.有很多便宜的解决方案,亚马逊有自己的服务,谷歌也有。 You can try first without even having to pay a cent.您可以先尝试,甚至无需支付一分钱。

I found the following from apple developer guide.我从苹果开发者指南中找到了以下内容。 This should answer your question -这应该回答你的问题 -

  1. Does Bonjour work between multiple subnets? Bonjour 是否可以在多个子网之间工作?

Yes.是的。 The first release of DNS Service Discovery (DNS-SD) for Mac OS X concentrated on Multicast DNS (mDNS) for single-link networks because this was the environment worst served by IP software.用于 Mac OS X 的 DNS 服务发现 (DNS-SD) 的第一个版本专注于单链路网络的多播 DNS (mDNS),因为这是 IP 软件所服务的最差环境。 Starting in Mac OS X 10.4, Bonjour now uses Dynamic DNS Update (RFC 2316) and unicast DNS queries to enable wide-area service discovery.从 Mac OS X 10.4 开始,Bonjour 现在使用动态 DNS 更新 (RFC 2316) 和单播 DNS 查询来启用广域服务发现。

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

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