在不同的网络上使用套接字通信 [英] Use Socket-communication over different networks

查看:105
本文介绍了在不同的网络上使用套接字通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,stackoverflowers!

Hello fellow stackoverflowers!

我目前正在开发该应用程序,该应用程序应该能够在设备之间进行通信.我发现很酷的指南如何使用Socket进行此类通信.而且有效!..ish.

I'm currently developing this app that should be able to communicate device-to-device. I found this cool guide on how to use Socket for that kind of communication. And it worked! ..ish.

我的问题是,仅当两个设备连接到同一Wi-Fi时,它才能工作.糟透了...因此,如果设备A是服务器&设备B是客户端,我使用内部IP地址(例如192.168.1.blahblahbla),即可正常工作.

My problem is that it only works while the two devices is connected to the same Wi-Fi. Which sucks... So if device-A is the server & device-B is the client, and I use the internal-IP address (like, 192.168.1.blahblahbla), it works.

-That's awesome, then why're complaining bro?

好吧,我希望能够连接到设备A的外部IP,即真实IP(例如94.254.blabla.blabla).所以我对你们的问题是,我该怎么做?我该如何做才能做到这一点?

Well, I want to be able to connect to device-A's external-IP, the real IP (like 94.254.blabla.blabla). So my question to you guys, is how do I do that? How can I do something that can make this happen?

所有帮助都会得到体现,预先感谢.

All help will be appriciated, thanks in advance.

很高兴,芒斯.

推荐答案

这更像是一个网络问题,但答案是没有区别.您唯一需要面对的不同就是防火墙保护.如果您可以使用私有IP而非公共IP连接到设备,则意味着存在某些阻止您连接的信息(可能是防火墙或路由器的防火墙).

This is morelike a networking question, but the answer is that there's no difference. The only different thing you have to bare with is with a firewall protection. If you can connect to a device using private IPs and not public, this means there's something blocking your connection (probably a firewall or the router's firewall).

您必须确保在目标设备上连接的端口没有被阻塞.其余的都一样.

You have to make sure the port you're connecting on the destination device is not blocked for your connection. The rest is the same.

这篇关于在不同的网络上使用套接字通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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