Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
How to send user specific data using SSE

i am trying to create a social media page where in home page of every user they can see feeds,

feeds from friend's post. when ever my friend create a post i can see the same in my feeds in real time.

For that i am using SSE in python flask. everything working find but after adding few more users only i realise all the post are coming to all logged in people's feed. which wrong, i want to see feeds from only my friends.

Can any one help me how to achieve it. i am sharing the base level code of python and java script.

Client side:

var source = new EventSource("http://172.19.0.3:8044/events");

source.addEventListener('user_feeds', function(event) {
    var data = JSON.parse(event.data);
    console.log("Even from server ");
    console.log(data);
}, false);

Server side

from flask_cors import CORS
from flask_sse import sse
from factory import create_app
app = create_app()
CORS(app)
app.config["REDIS_URL"] = "redis://redis"
input_user_feeds = dict()
app.register_blueprint(sse, url_prefix='/events)
PROMOTION_BLUEPRINT = Blueprint('my_page', __name__, url_prefix='/api/v1/')


@PROMOTION_BLUEPRINT.route('/feeds/<user_id>', methods=["GET"])
def feeds(user_id):
    push_feeds(user_id)
    return "SUCCESS"


@PROMOTION_BLUEPRINT.route('/user_request/<user_id>', methods=["POST"])
def user_request(user_id):
    data = request.json
    add_feeds(user_id, data)
    return "SUCESS"


def push_feeds(user_id):
    while 1 == 1:
        if user_id in input_user_feeds:
            input_request = input_user_feeds[user_id]
            sse.publish(input_request, type='user_feeds')
            del input_user_feeds[user_id]


def add_feeds(user_id, data):
    input_user_feeds[user_id] = data


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=Config.PORT, debug=True)

I trued to do with single user id. but that is also not a good idea. It will be helpful if anyone having good knowledge in SSE help me find the solution.

Thanks in advance.


about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda