From: Bino O. <bi...@in...> - 2010-08-31 06:00:54
|
Dear All. I play with JabberBot from your example. I try to make this bot do other thing than just replaying the caller. Now .. I need to expand this bot to also listen to a TCP-Port I adopt the socket server from example 20.17.4.3 of <http://docs.python.org/library/socketserver.html> http://docs.python.org/library/socketserver.html what i did is : 1. in jabberbot.py at the bottom, I add ----START---- class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler): def handle(self): data = self.request.recv(1024) cur_thread = threading.currentThread() response = "%s: %s" % (cur_thread.getName(), data) #self.request.send(response) #Lets try to FORWARD data incoming via TCP port to others at the XMPP side JabberBot.send('bi...@ja...', data) class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass ----STOP----- 2. in broadcast.py Inside --> class BroadcastingJabberBot at the bottom part of --> def __init__( self, jid, password, res = None): I add ---START---- HOST, PORT = "localhost", 50008 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) ip, port = server.server_address # Start a thread with the server -- that thread will then start one # more thread for each request server_thread = threading.Thread(target=server.serve_forever) # Exit the server thread when the main thread terminates server_thread.setDaemon(False) server_thread.start() print "Server loop running in thread:", server_thread.getName() #-------End of socket server ----STOP----- I try to run the broadcast.py .. looks fine Next, from another shell .. I try to do --> bino@erp:~/Documents$ echo "it's me" |nc 127.0.0.1 50008 At the bot shell , I got this error : -----START----- Exception happened during processing of request from ('127.0.0.1', 51188) Traceback (most recent call last): File "/usr/lib/python2.6/SocketServer.py", line 558, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.6/SocketServer.py", line 615, in __init__ self.handle() File "/home/bino/Documents/iwic/kode/jb01/jabberbot.py", line 506, in handle JabberBot.send('bi...@ja...', data) TypeError: unbound method send() must be called with JabberBot instance as first argument (got str instance instead) ------STOP------ So , Kindly please tell me what I have to do to fix this problem. Sincerely -bino- |