E
E
Evgeny Elizarov2013-01-23 09:52:34
Python
Evgeny Elizarov, 2013-01-23 09:52:34

Twisted and new to python: a couple of questions

Hello everybody. I'm a beginner, I just took a couple of courses in a python specialist, there is a little theory, but with practice it's really sad, there are a couple of questions about this. I have a php project that works as a “server application”, because work with icq/jabber on php is implemented, to put it mildly, not very well, and notifications to the system, in addition to mail, need to be fastened. It was decided to write some im gateway and set it up on my server so that notifications would be sent through it. As a result, I have 2 questions:
1. How can I implement the transfer of data to the script? Probably it needs to be raised as a demon so that it listens to a certain port and reacts to the information coming there (as I understand it, this can be implemented using the same twisted). But I’m not at all boom-boom in this, so I don’t even know which way to google yet, so I’ll be grateful for the advice.
2. In general, so far the most important question - so far I have started “from the end” so to speak: sending messages to users. I took twisted, twisted it, looked at the example, as a result, there is a small piece of code that sends the right message to the right ICQ number, so all that remains is to transfer data to it, but so far it only responds to a message to its icq number (i.e. work in the mode of a responding bot, as described 100500 times in Google), but I can’t figure out how to “manually” force him to send a message. Where and how the receiveMessage() function is called to send a message and what parameters are passed there, I still can’t understand (I suspect that all this comes from the insides of twisted itself, so I don’t know how to work with it).

I ask you not to kick your legs too much, this is my first practical work in python.
For clarity - code: pastebin.com/mEDyamKm

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arkady, 2013-01-23
@p0is0n

For you, you need to start here: twistedmatrix.com/documents/current/core/howto/servers.html

class ReceiverProtocol(LineReceiver):

    def lineReceived(self, line):
        botObject.sendMessage(SendTo, line)


class ReceiverFactory(Factory):

    protocol = ReceiverProtocol


reactor.listenTCP(LISTEN_PORT,  ReceiverFactory())

Next: Send TCP "any message\r\n" to port LISTEN_PORT

A
alz, 2013-01-23
@alz

You can raise the xmlrpc server in the same script. In the initDone method, register an icq connection instance (self variable) in this rpc server and implement an rpc method that will pull the sendMessage method of the registered connection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question