Help with Python Flask on PI as server SSE to website

Joined
Apr 23, 2022
Messages
1
Reaction score
0
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

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"
        time.sleep(1)

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

if __name__ == "__main__":
    app.run(host='0.0.0.0',port=1050)


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

Code:
<!DOCTYPE html>
<html>
<body>

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

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

</body>
</html>

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?


itworkslocal.jpg
 

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

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top