question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client could not receive emits from the server.

See original GitHub issue

i am learning flask now and i have a big problem. i use flask and flask-scoketio. my client could not receive emits from the server. i dont know why. the websocket is Upgrade

(10728) accepted ('127.0.0.1', 52781)
(10728) accepted ('127.0.0.1', 52782)
127.0.0.1 - - [01/Mar/2017 16:14:38] "GET / HTTP/1.1" 200 5263 0.010000
127.0.0.1 - - [01/Mar/2017 16:14:38] "GET /static/web.css HTTP/1.1" 200 6780 0.219000
111c03a0438947ecae776c4103091c37: Sending packet OPEN data {'pingInterval': 25000, 'pingTimeout': 60000, 'upgrades': ['websocket'], 'sid': '111c03a0438947ecae776c4103091c37'}
111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 0
127.0.0.1 - - [01/Mar/2017 16:14:38] "GET /socket.io/?EIO=3&transport=polling&t=Lg8xtLu HTTP/1.1" 200 381 0.001000
(10728) accepted ('127.0.0.1', 52784)
111c03a0438947ecae776c4103091c37: Received request to upgrade to websocket
111c03a0438947ecae776c4103091c37: Sending packet NOOP data None
111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"hello"}]
111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":"welcome"}]
127.0.0.1 - - [01/Mar/2017 16:14:38] "POST /socket.io/?EIO=3&transport=polling&t=Lg8xtM9&sid=111c03a0438947ecae776c4103091c37 HTTP/1.1" 200 219 0.002000
127.0.0.1 - - [01/Mar/2017 16:14:38] "GET /socket.io/?EIO=3&transport=polling&t=Lg8xtMA&sid=111c03a0438947ecae776c4103091c37 HTTP/1.1" 200 260 0.000000
(10728) accepted ('127.0.0.1', 52785)
127.0.0.1 - - [01/Mar/2017 16:14:38] "GET /favicon.ico HTTP/1.1" 404 366 0.000000
111c03a0438947ecae776c4103091c37: Upgrade to websocket successful

when i click in client,the emits is empty 111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"one"}] 111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":""}] 111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"two"}] 111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":""}] 111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"three"}] 111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":""}] 111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"four"}] 111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":""}] 111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"five"}] 111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":""}] 111c03a0438947ecae776c4103091c37: Received packet MESSAGE data 2["message",{"data":"six"}] 111c03a0438947ecae776c4103091c37: Sending packet MESSAGE data 2["server_response",{"data":""}]

here is the code

server:

@socketio.on('message')
def connectevent(job_name):
    if job_name['data'] == 'hello':
        emit('server_response', {'data': 'welcome'})
    else:
        log_command = ['ping','-t','192.168.4.1']
        log_out = subprocess.Popen(log_command, stdout=subprocess.PIPE)
        while log_out:
            out = log_out.stdout.readline().strip()
            emit('server_response', {'data':out})

the out could not print fully and the emits could not send,it only print

111c03a0438947ecae776c4103091c37: Received packet PING data None
111c03a0438947ecae776c4103091c37: Sending packet PONG data None
111c03a0438947ecae776c4103091c37: Received packet PING data None
111c03a0438947ecae776c4103091c37: Sending packet PONG data None
111c03a0438947ecae776c4103091c37: Received packet PING data None
111c03a0438947ecae776c4103091c37: Sending packet PONG data None
111c03a0438947ecae776c4103091c37: Received packet PING data None
111c03a0438947ecae776c4103091c37: Sending packet PONG data None

if i replace while with if , it works,but it only send one line to client.

client

var socket = io.connect('http://' + document.domain + ':' + location.port);
var name = 'hello'

function jobname(name){
    socket.emit('message',{'data':name});
    return false;
};

socket.on('connect', function() {
    socket.emit('message',{'data':name});
})

socket.on('server_response', function(msgg) {
    console.log(msgg)
    $('#loog').append('<br>' + $('<div/>').text(msgg.data).html());
});

thanks everyone

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelgrinbergcommented, Mar 5, 2017

@kyouko-taiga you can’t use regular networking and threading functions when you use eventlet, because those are blocking. Your best shot is to see if monkey patching resolves the problem. Just add the following as the first lines of your script (above all your other imports):

import eventlet
eventlet.monkey_patch()
1reaction
miguelgrinbergcommented, Mar 1, 2017

Are you using eventlet or gevent? If you are, add a socketio.sleep(0) after the emit in your loop. That will release the CPU and let other tasks do their work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

flask-socketio --> Client not receiving emits from server
So I would expect that on client side, 'socket.on('updateData'...)' gets triggered and messages 'called UpdateData', 'this the data to show - ...
Read more >
why the client can not receive the emit data during connecting?
The server is sending a normal message with the string "i deny u ". This isn't what I expect would be sent when...
Read more >
Client API - Socket.IO
A Socket is basically an EventEmitter which sends events to — and receive events from — the server over the network. socket.emit("hello", { ......
Read more >
The Socket.IO Server — python-socketio documentation
A limitation of the write-only client manager object is that it cannot receive callbacks when emitting. When the external process needs to receive...
Read more >
io.emit() not emitting data to all clients : r/node - Reddit
Suppose think I have two clients connected to the server. If one client gets message another client will not get that.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found