stephenmcd / django-socketio

WebSockets for Django
BSD 2-Clause "Simplified" License
1.32k stars 244 forks source link

Please guide me here to push message to client #82

Closed rajasimon closed 9 years ago

rajasimon commented 9 years ago

Hi

I just installed everything django-socketio asks now my code is:

result.html

<script type="text/javascript">
      var socket = new io.Socket();
      socket.connect();
      socket.on('connect', function() {
          socket.subscribe('my channel');
      });
      socket.on('event', function(data){
          console.log(data);
      });
      socket.on('disconnect', function(){
          // alert('Disconnectded');
      })
</script>

Views

def result(request):
    return render(request, 'result.html')

import django_socketio as socket
def publish_result(request):
    socket.broadcast_channel('my message here', channel='my channel')
    return HttpResponse("Yes published")

Ok then

when I hit the publish_result url my message will sent to my channel right ? then why console.log(data) always empty ?

Is my method and logic correct..? Please guide me here

stephenmcd commented 9 years ago

https://github.com/stephenmcd/django-socketio/blob/master/django_socketio/example_project/chat/static/js/chat.js#L107