简体   繁体   English

我应该使用套接字直接连接两部Android手机吗?

[英]Should i connect two Android phones directly using Sockets

I want to make a communication between two Android phones directly on WIFI. 我想在WIFI上直接在两部Android手机之间进行通信。 These two Android phones are not in the same network. 这两款Android手机不在同一个网络中。 I have gone through this post 我已经完成了这篇文章
Incorporating Socket Programming into your Applications : Android 将套接字编程融入您的应用程序:Android

I assume that we can connect two Android phones using socket. 我假设我们可以使用socket连接两部Android手机。 But i dont know what are possible limitations for direct sockets. 但我不知道直接插座有什么可能的限制。
Will it work no matter where the two devices are and what are their IP addresses ? 无论两台设备在哪里以及它们的IP地址是什么,它都能工作吗?
Does Android allow for incoming connection if i make it a Server ? 如果我将它作为服务器,Android是否允许传入连接?
Is it a good idea to connect two phones directly using Sockets ? 使用套接字直接连接两部手机是个好主意吗?

Will it work no matter where the two devices are and what are their IP addresses ? 无论两台设备在哪里以及它们的IP地址是什么,它都能工作吗?

It should, even if you are on a private network, as long as you have your port forwards set correctly on each internal route. 即使您在专用网络上,只要您在每个内部路由上正确设置了端口转发,它应该是。

Does Android allow for incoming connection if i make it a Server ? 如果我将它作为服务器,Android是否允许传入连接?

It should 这应该

Is it a good idea to connect two phones directly using Sockets ? 使用套接字直接连接两部手机是个好主意吗?

I don't see why not 我不明白为什么不

Give it a try! 试试看! You might see some issues with your ISP or carrier only allowing certain ports through, try 80, 443, or 22 if higher port numbers are giving you problems. 您可能会发现ISP或运营商的某些问题只允许某些端口通过,如果更高的端口号给您带来问题,请尝试80,443或22。

It is possible to connect two Android devices using Sockets but as you want to connect them on WIFI and over WIFI you won't have a static IP address and this will create a problem for you if in any case IP address of server is changed. 可以使用套接字连接两个Android设备但是由于您希望在WIFI和WIFI上连接它们,您将没有静态IP地址 ,如果在任何情况下服务器的IP地址发生更改 ,这将为您带来问题
Another problem is that if your Android server has a private IP address then you will not be able to connect to android server. 另一个问题是,如果您的Android服务器有私有IP地址,那么您将无法连接到Android服务器。 I am not sure but i assume every Android has a private IP address 我不确定,但我认为每个Android都有一个私有IP地址

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

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