views:

245

answers:

3

Hey,

Im trying to write a program that would be listening for data (simple text messages) on some port (say tcp 6666) and then pass them to one or more different protocols - irc, xmpp and so on. I've tried many approaches and digged the Internet, but I cant find easy and working solution for such task.

The code I am currently fighting with is here: http://pastebin.com/ri7caXih

I would like to know how to from object like:

ircf = ircFactory('asdfasdf', '#asdf666')

get access to self protocol methods, because this:

self.protocol.dupa1(msg)

returns error about self not being passed to active protocol object. Or maybe there is other, better, easier and more kosher way to create single reactor with multiple protocols and have actions triggeres when a message arrives on any of them, and then pass that message to other protocols for handling/processing/sending?

Any help will be highly appreciated!

+1  A: 

See doc/core/examples/chatserver.py. There they've added hooks to the Protocol's connectionMade and connectionLost methods to maintain a list of connected clients, and then it iterates through all of them when a message arrives to pass on.

keturn
I think, it does not resolve my issue - what that example does, is sending a message to every connected client in range of one protocol. What I am trying to do, is to receive a text line on some port, and then pass it to two or more different protocols, where it could be processed according to protocols defined methods when receiving a message - like pasting received line to irc channel, sending via xmpp to jabber clients, and so on.
SpankMe
So you'll have to do what the example does, in terms of keeping track of the connected clients (on each protocol), but also add some higher-level object that keeps track of all of those. That might be a `Service` you create that holds reference to your `irc` and `nagios` factories, and passes messages to them.
keturn
Well - it seems that I am not explaining the issue simply enought. This code aims to be listening on port 6666 and at the same time logged on irc (lets drop the jabber thing for now) as a bot, that will send message received on port 6666 to irc channel he will be logged on. This is not an issue of sending messages between multiple clients in one protocol, but passing data between two (or more) independent protocols/factories. I hope this helps to understand the issue behind the code.
SpankMe
A: 

Hi ... I Also have the same need. And still found no solution about it. Actualy the bot part is taken from here

Need to add socket server that sit on a TCP port so that if I make --> echo "it's me" |nc localhost 50008

It'll forwarded to [email protected]

Currently I'm trying to understand twistedmatrix.com/documents/current/core/howto/tutorial/factory[dot]html (Sorry, I only allowed one link.)

Still not find the right way to replace the IIRC part with document above

I wish somebody can give any enlightment

bino