问题
I'm using pyramid to build up a web site and would like to find some modules about sending messages between users accounts in my web site. I've heard that rails has some gems for that such like https://github.com/ging/mailboxer or https://github.com/pluginaweek/has_messages .
I would like to find the python one. Can anyone recommend me some python modules? Thanks!
回答1:
You're probably best off using an existing protocol like XMPP. For Plone (a Python CMS) for example there's a complete XMPP integration with collective.xmpp.chat providing multi-user chat and Instant Messaging between authenticated users of a Plone site (demo video).
For Pyramid you'll need to do this integration yourself [1]
, by running a Jabber / XMPP server (such as ejabberd) and using an existing XMPP client library for Python to communicate with it. There are plenty of XMPP libraries for Python, some of them are described in the answers to this question.
Note: Don't be scared if after looking at XMPP it looks way to complex. XMPP and its extension describe a wide variety of features related to Messaging and Presence, chat is just one of them. If you don't need the other features, simply don't implement them in your webapp.
[1]
Actually, there is a Pyramid project that seems to do exactly that: seshat, written by @KirkStrauser. I haven't used it myself, but it looks very promising.
回答2:
No; direct communication between two individuals isn't possible in web applications because they use stateless protocols; the server does not know if the request is coming from the same person or not.
That being said, what chat applications usually do is store the communications within a database between the 2 individuals, and use AJAX to retrieve them.
There are already lots of chat application tutorials and 3rd party chat application packages online; you might want to check them out.
来源:https://stackoverflow.com/questions/12607317/is-there-any-python-module-for-sending-messages-between-users-in-a-web-applicati