Use Socket-communication over different networks

℡╲_俬逩灬. 提交于 2019-12-13 17:25:08

问题


Hello fellow stackoverflowers!

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.

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?

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.

Sincerly, Måns.


回答1:


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.



来源:https://stackoverflow.com/questions/22234520/use-socket-communication-over-different-networks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!