Open mariotti opened 7 years ago
@mariotti please, format your snippet and add invocation example.
Respect time of other people. Thanks
@oblalex I am very sorry, formatted! I was trying but got troubles and had to leave the keyboard.
Came to my mind a possible problem, does the client need to start the exchange? Like sending a first message like "ready to receive".
Solved part of the problem, I mean part of mine ;) , but I am not sure about the actual behaviour of flask-sockets. This snippet works:
@sockets.route('/wscrd')
def echo_crd(ws):
print "HERE!"
vcamera = VideoCamera()
pframes = ProcFrames(vcamera)
while not ws.closed:
#message = ws.receive()
ws.send("|Start loop|")
while True:
xred, yred, xyellow, yyellow = pframes.get_frame_crd(ws)
ws.send(str(xred))
But wait... the client now is sending a first message to the server, even if it doesn't get read.
Once opened a ws connection, is it possible to start with just the server sending data? I mean, even by protocol. Does websocket need to have the client starting with a first data?
This in relation to my last comment.
From this document mozilla.org / Writing_WebSocket_servers
it seems that the server can start sending data. Quote:
" Either the client or the server can choose to send a message at any time — that's the magic of WebSockets. "
I am trying to serve on websocket only websockets. The code looks like this:
Or very close.
The js code gets connected and immediately disconnected. The /wscrd route is never hit.
The js code is very plain. Please note that the content of the loop
while True:
had many different versions... a kind of trial and error .. this is just one. But it never gets called anyway.I add the js code for refs:
On the js client side I see the 2 alert: "On_open" and "On_close".