php - Redis Pub/Sub with Python backend and Socket.io -
i have php code publishes data channel called "message_from_mars". snippet follows :
function send_data_to_check_spam($feedback) { $d_id=$this->redis_connect(11); //echo $feedback; //die(); echo "<b style='color:red'>message sent spam swatter</b>"."<br>"; $d_id->publish("message_from_mars",$feedback); }
there server side python listener receives published data , snippet follows :
r = redis.strictredis(host='localhost', port=6379, db=11) def sum(a,b): print a+b def main(): sub = r.pubsub() sub.subscribe('message_from_mars')
the python code processing , publishes result back. snippet follows :
r.publish('spam_status',spam)
i trying result using socket.io websocket , snippet follows. :
<script> var socket = io.connect('127.0.0.1:6379'); console.log(socket); socket.on('spam_status', function (data) { alert("here"); console.log(data); //socket.emit('my other event', { my: 'data' }); }); </script>
everything works peach except socket.io reason not getting message spam_status channel.
what doing wrong? relatively new socket.io, pardon naivety
as far know, need socketio server on server side.
so apparently, "var socket = io.connect('your redis port')" won't work.
redis comes in pub/sub part, server->server broadcast.
for realtime interaction between server , client side, need socketio server , socketio client.
this working example find useful myself:
https://github.com/jonashagstedt/redis-pubsub-chat/tree/master/redischat
Comments
Post a Comment