fanout / django-eventstream

Server-Sent Events for Django
MIT License
650 stars 85 forks source link

EventSource constantly losing connection #7

Closed vacovnik closed 6 years ago

vacovnik commented 6 years ago

I was trying out django-eventstream on a raspberry and installed pushpin and all it's dependencies directly from ppa.

Pushpin works if I use curl or pushpin-publish, but with chat example, I can not get it to work. I just constantly get

*** connected
*** connection lost, reconnecting...

messages.

jkarneges commented 6 years ago

Hi,

Make sure you connect to the chat example through Pushpin. The behavior you describe sounds like you might have pointed a browser directly at the backend Django app?

vacovnik commented 6 years ago

Hi, Thank you to for a fast response!

The thing is that I am running raspbian lite with no display, so I am accessing a page from another computer. As you mentioned that, I went through all the steps again and noticed that --route flag overrides routes file, where I still had * test line. When I deleted it, application started to work.

The point is that django app I am trying to integrate django-eventstream in is running on a windows machine, and I would like to use raspberry just for pushpin. So if I want to achieve that, I must direct my browser to raspberry ip on routed port?

jkarneges commented 6 years ago

Glad you got it working. :)

The point is that django app I am trying to integrate django-eventstream in is running on a windows machine, and I would like to use raspberry just for pushpin. So if I want to achieve that, I must direct my browser to raspberry ip on routed port?

Technically only the events endpoint needs to be accessed through Pushpin. You could load the website directly from the Windows machine if you want, as long as your JS code passes a full URL to the EventSource constructor to connect to the Pi for events.

Edit: if you pass a different server to EventSource, be sure the events endpoint supports CORS. One way is to enable the auto cross origin feature in Pushpin.

vacovnik commented 6 years ago

I tried what you propose at the very beginning and didn't work, because of the previously stated error. I had some trouble figuring out the right address, and came nowhere, so I decided to do it the other way.

At the end the whole server will run on Pi, so I think it is better as it is. But now - for developing purposes - it's better to code on computer with IDE than on headless machine via terminal...:)

Thank you very much for all the help and clarification.