Help with Python Flask on PI as server SSE to website

Apr 23, 2022
Reaction score
First time post, long time guest. Sorry if there is a specific location for this type of question, I did a pretty hardcore search for my issue I keep facing but nothing geared specifically to my issue.

I am running a PI on my local network running flask SSE server. I have it running on a private port on its local network. This private port has been port forwarded on the gateway it is connected to for a public ip > private ip. I am able access this server and see the events posting using this "http://WAN:pUBLICIP". Now, I would like to have this SSE utilized on a shared hosting domain that I own (sockets are not an option).

First code is my PI starting the flask server
second code

import sys, datetime, time, flask

app = flask.Flask(__name__)

def event_stream():
    while True:      
        ir = 150
        yield "data: " + str(ir) + " #%d @ %s\n\n"

def stream():
    return flask.Response(event_stream(), mimetype="text/event-stream")

if __name__ == "__main__":'',port=1050)

Now, I have a domain with a CPanel I would like to point my Event stream client to.

<!DOCTYPE html>

<h1>Getting server updates</h1>
<div id="result"></div>

if(typeof(EventSource) !== "undefined") {
  var source = new EventSource("WANIP:PUBLICPORT");
  source.onmessage = function(event) {
    document.getElementById("result").innerHTML += + "<br>";
} else {
  document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";


just a white screen..

Admittedly I know nothing about SSE but am halfway fluent in Python so this HTML code was an example used on W3schools as I tried to understand Event Streams. There's plenty of documentation from PHP to PHP or .JS event streams but for some reason my FLASK code will not trigger an event on my domain. Here is a screenshot when I visit my web broser (WANIP:pUBLICPORT) which posts every second as the server responds. How can I get this to my domain instead of using the WAN address?


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads