TCP P2P without server

自古美人都是妖i 提交于 2019-11-29 15:43:06

问题


is it possible to write TCP P2P program without server? When I was googling this question I found something about NAT traversal,UPnP, can I use them somehow?


回答1:


Yes you can (where as GrandmasterB points out, each peer has both server and client sockets). However, NATs will cause you pain, as you may already know.

If you can't use middleboxes (servers on public IP addresses to which your clients connect (*)) - and you might not want these, because they're rather contrary to the point of P2P - and you don't mind describing your connection details with SDP, you could try Interactive Connectivity Establishment.

Essentially, ICE tries different strategies to connect. It's a pluggable architecture, so you could add your own custom strategies. By default ICE describes techniques for UDP traversal, but an extension to allow TCP connectivity is in the works.

(*) You could always try an architecture like IRC, where you have any number of servers peering amongst themselves, to which clients connect. That's halfway to P2P at least. (This is also pretty much the architecture SIP uses.)




回答2:


It really depends what you mean by 'server'. You dont need a centralized server by any means. The term 'p2p', by its very definition, implies no centralized server.

But the apps that receive data from other apps need to be able to listen for incoming tcp/ip connections... thats typically considered 'server' functionality, even if you arent calling it a 'server'. So in your case, your p2p app would need to have both server and client (initiating connections) capabilities built into it.



来源:https://stackoverflow.com/questions/3392016/tcp-p2p-without-server

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