是否可以通过互联网在两个移动设备(iPhone)之间连接插座? [英] Is it possible to connect a socket between two mobile devices (iPhones) over the internet?

查看:126
本文介绍了是否可以通过互联网在两个移动设备(iPhone)之间连接插座?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过互联网在两个移动设备(iPhone)之间连接套接字?

Is it possible to connect a socket between two mobile devices (iPhones) over the internet?

我正在尝试发现每个设备的IP并直接连接。我知道可以用Bonjour完成,但这只适用于本地网络。我需要通过互联网在两台设备之间建立高速连接。

I am trying to discover the IP of each device and connect directly. I know it can be done with Bonjour but that only works on local networks. I need a high speed connection between two devices over the internet.

谢谢。

推荐答案

如果你同时拥有IP和他们两者都是可以路由的,应该是可能的。我不确定3G网络发出的IP是否可路由。如果您使用的是WIFI,那么您获得的IP几乎肯定不可路由。假设你有一个可路由的IP,它应该是可能的。

If you had both the IP's and they were both routable, it should be possible. I'm not sure though if the IP's given out by the 3G network are routable. If you are using WIFI, the IP you get is almost certainly not routable. Assuming you have a routable IP though, it should be possible.

诀窍就是发现另一个设备的IP。最好的方法可能是让每个设备在你的应用程序启动时使用Web服务注册其IP,然后查询该服务以查找其他设备的IP。

The trick is just discovering the IP of the other device. The best way to do that would probably be to have each device register its IP with a web service when your app starts up, then query that service to find the IPs of other devices.

当应用程序关闭或IP更改时,管理取消注册IP可能会有点棘手,但它应该是可行的。

It might get a bit tricky managing "unregistering" IPs when the app is closed or when an IP changes though, but it should be doable.

ETA:

如果你有一台可以连接的服务器,你应该能够使用该服务器实现一个解决方案(即没有电话实际上直接连接到彼此)。这样可以避免为手机提供可路由的IP。

If you have a server that they can both connect to, you should be able to implement a solution using that server (i.e. without the phones actually directly connecting to each other). This would avoid the issue of having routable IPs for the phones.

至于如何将套接字桥接在一起 - 您的服务器程序基本上就像老式电话交换机一样工作运营商。你有一些注册和服务器软件中内置的发现协议,允许手机向服务器注册自己,查询当前连接到服务器的其他手机列表,指出要与之通话的手机,以及接受来自其他手机的连接。

As for how to bridge the sockets together - your server program would basicly work like an old-school phone switchboard operator. You'd have some kind of registration & discovery protocol built into the server software that would allow a phone to register itself with the server, query a list of the other phones currently connected to the server, indicate which phone it wants to talk to, and accept connections from other phones.

一旦知道谁想与谁交谈,你的服务器软件会通过从一个手机的插座读取并将这些数据写入另一个手机的插座来将两者连接在一起。

Once it knows who wants to talk to whom, your server software would connect the two together by reading from one phone's socket and writing that data to the other phone's socket.

这篇关于是否可以通过互联网在两个移动设备(iPhone)之间连接插座?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆