i'm trying build simple chat app using nodejs server socket.io , client written in python 2.7 using socketio-client package. js server on local , simple :
io.on('connection', function(socket){ socket.on("chat_message", function(msg){ io.emit("chat_message", msg); }); }); this chat app works several pages opened in browser. (source comes : http://socket.io/get-started/chat/ )
i wanted connect server python client, , succesfully emit python js server (text entered in python client appears browser).
the problem following : when type text browser, python doesn't print shell.
here code use on python side :
def communicate(self, msg): logging.debug('processing event : %s', msg) self.socketio.emit("chat_message", msg, self.on_chat_message) def on_chat_message(self, *args): output = '' index = 0 in args: output += ' | '+str(index)+' : '+str(a) index += 1 logging.debug('processing server output : ' + output) return as server emits connected clients, python should handle callback 'on_chat_message' but, doesn't work.
i tried add self.socketio.wait_for_callbacks() python, without success.
if has idea i'm doing wrong, great =d ! thanks.
i managed response server on python client.
my mistake not 'wait' on socketio variable, didn't catch feedback.
to handle server responses, use basenamespace class binded socket, , handle basic events : overriding of function on_event
def on_event(self, event, *args): #catch event , stuff if event handled class, flag raised , checked client.
def communicate(self, msg): self.socketio.emit('chat_message', msg) def wait_for_server_output(self): while(1): self.socketio.wait(seconds=1) ns = self.socketio.get_namespace() if ns.flag.isset(): data = ns.data_queue.get() ns.flag.clear() these 2 functions managed 2 threads inside client code.
hoping =)
Comments
Post a Comment