开发者

Writing a P2P chat application in Python

开发者 https://www.devze.com 2023-01-26 14:29 出处:网络
Is it possible to write a peer-to-peer chat application in Python? I am thinking of this from a hobbyist project point-of-view. Can twomachines connect to eac开发者_如何转开发h other directly withou

Is it possible to write a peer-to-peer chat application in Python?

I am thinking of this from a hobbyist project point-of-view. Can two machines connect to eac开发者_如何转开发h other directly without involving a server? I have always wondered this, but never actually seen it implemented anywhere so I am thinking there must be a catch somewhere.

PS: I intend to learn Twisted, so if that is involved, it would be an added advantage!


Yes. You can do this pretty easily with Twisted. Just have one of the peers act like a server and the other one act like a client. In fact, the twisted tutorial will get you most of the way there.

The only problem you're likely to run into is firewalls. Most people run their home machines behind SNAT routers, which make it tougher to connect directly to them from outside. You can get around it with port forwarding though.


Yes, each computer (as long as their on the same network) can establish a server instance with inbound and outbound POST/GET.


I think i am way too late in putting my two bits here, i accidentally stumbled upon here as i was also searching on similar lines. I think you can do this fairly easily using just sockets only, however as mentioned above one of the machines would have to act like a server, to whome the other will connect.

I am not familiar with twisted, but i did achieved this using just sockets. But yes even i am curious to know how would you achieve peer2peer chat communication if there are multiple clients connected to a server. Creating a chat room kind of app is easy but i am having hard time in thinking how to handle peer to peer connections.

0

精彩评论

暂无评论...
验证码 换一张
取 消