Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

android - P2P chat application which works on wide network over internet

I want to build a p2p mobile phone chat application which can connect different users accross the globe over internet.I searched the web but didnt comeacross anything i specifically want to. I found somany p2p approaches using wifi,bluetooth,nfc etc but these can only be implemented in small area only. I also found an approach that only uses a server to update the address of connected devices.But i want to build a chat application which is completely without any servers and users accross different part should be able to connect over internet. I dont know any connection establishment mechanism if exist to do so. Please help me to find a solution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is not a new subject anymore, people have spent a lot of time on this subject, but there is still no perfect solution.

NAT prevents us to connect to each other directly.

Let me try to explain it:

Just assume you have two peers A, B, which want to establish a connection.

In a real network environment, A and B will be both behind the NAT, so they cannot connect to other with the local area network IP address(such as 192.168.. or, 10.0..).

To solve the above problem, people try to fire a public servers(C) to get the public IP addresses of A and B.

(1) A connects to C, we can get A's public IP address from the C.

(2) B connects to C, we can get B's public IP address from the C.

(3) Then C sends A's public IP to B, sends B's public IP to A. After that, A and B get the public IP of each other.

(4) Then A and B can establish a connection with the public IPs.

But that depends on the NAT's implementation.

For some types of NAT implementation, the A and B's public IPs may change. The public IPs of A/B will keep unchanged only if the current connection is not disconnected, which means even if we exchange the A/B's public IPs to each other by Server C, A and B cannot connect to each other.

Explaining the NAT in detail may need a lot of words, please ref https://en.wikipedia.org/wiki/Network_address_translation. section "NAT implementation classifications".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...