在路由器后面的android socket编程 [英] android socket programming behind a router

查看:271
本文介绍了在路由器后面的android socket编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一个问题或问题。我想提出两个Android手机之间的点到点的连接。我的每部手机连接到我的服务器和我得到他们的私人(192.168.1.1),公共(76.123.288.22)IP,并连同它们连接到我的服务器的端口。我送一个应答当手机连接到服务器与一个特定的端口打开服务器套接字。我也送了对方手机打开的套接字的公网IP​​和端口,但它不连接。我已阅读多线程就在这里,这是不可能做到点到点的连接,如果两个手机和电脑背后两个不同的路由器。我的问题是,如果这是真的,如果是怎样的LogMeIn或其它P2P应用程序的工作不同的路由器后面?它是一个编程错误或网络架构不允许它?

Hey guys I have a question or problem. I am trying to make a p2p connection between two android phones. I have each phone connect to my server and I get their private (192.168.1.1) and public (76.123.288.22) IP and along with the ports that they connect to my server. I send a response when the phone connects to the server to open a server socket with a specific port. I also send the other phone the public IP and port of the open socket, but it does not connect. I have read multiple threads on here that it is not possible to do p2p connection if both phones or computers are behind two different routers. My question is if that is true and if so how does LogMeIn or the other p2p applications work behind different routers? Is it a programming error or the network architecture does not allow it?

推荐答案

有多种方法来实现这一目标 - STUN 开启,的 ICE 仅举几例。你可以了解他们每个人与软件,如Skype的,每增加等使用等等这些技术。

There are several techniques to achieve this - STUN, TURN, ICE to name a few. You can read about each of them and softwares such as skype, gtalk etc. use these techniques among others.

但主要的概念,在这里明白的是,

But the primary concept to understand here is,

  1. 您需要一个IP是的公开访问,让您可以连接到它的。如果它是一个专用网络上的路由器之后,则需要在路由器的,即你需要一个规则添加到路由器转发通信接收到特定端口到服务器后面的路由器上的端口转发。在一定程度上,上述技术实现这一隐式或通过涉及外部的第三方服务器

  1. You need an ip which is publicly reachable so that you can connect to it. If it is behind a router on a private network, then you need port forwarding on the router i.e. you need to add a rule to that router to forward traffic received on a particular port to your server behind the router. To a certain extent, the above techniques achieve this implicitly or by involving an external 3rd party server.

您需要的允许连接到最初的计算机上的传入连接的。一般Windows或Linux的防火墙阻止所有传入连接,除非有异常增加。这很可能需要为您的节点。

You need to allow incoming connections on the machine which is connected to at first. Generally windows or linux firewalls block all incoming connections unless an exception is added. This would probably be needed for both of your nodes.

在过去的一部分,我不计划在Android所以真的不知道,如果它允许传入的连接等,添加规则,但我确实知道,每增加一个有一个客户端,Android和Gtalk的使用XMPP其内部可以使用任何的技术,我指出以上。因此,没有理由相信它为什么不能为android手机来完成。

For the last part, i don't program on android so am not really sure if it allows adding rules for incoming connections etc. But i do know that gtalk has a client for android and gtalk uses XMPP which internally can use any of the techniques i pointed out above. So there is no reason to believe why it can't be done for android phone.

添加一些有用的参考资料:

Adding some more useful references:

libjingle 是由谷歌的开源库,可用于编写P2P应用,包括文本,音频和视频。

libjingle is an open source library by google which can be used to write p2p applications including text, audio and video.

这似乎都被编译为Android以及这里

It seems to have been compiled for android as well here

这篇关于在路由器后面的android socket编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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