-
Notifications
You must be signed in to change notification settings - Fork 287
Sending message from server to client when web socket is opened. #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi Tim, This is a little surprising. Do you have a paste of the termination message? Is there an exception perhaps? Also, which versions of ws4py and cherrypy are you running? |
I was hoping it was just user error. Here are the versions: CherryPy 3.2.6 Here's the log output when calling self.send() in the opened() callback:
It didn't really catch my attention earlier, but I'm not sure why once() would be called by send()? Or is it that send() is somehow leaving things in a bad state, and once() fails when it gets polled by the manager? Many thanks for the quick response. |
Mmmh, I don't know what to say. This is what the threadedclient short example does (calling send from the opened() callback) and it has always worked. Oo |
I hadn't noticed this example because I've been (perhaps overly) focused on the server side, but I'll give it a try. Cheers, |
Thanks. I'm honestly lost here, I don't see why this would fail. It seems your client closes its socket as soon as it's opened. |
Just ran into the issue myself, similar setup (CherryPy + ws4py). This is my WebSocket class: class XXWebSocket(WebSocket):
def opened(self):
cherrypy.log("VBWebSocket opened")
self.send(TextMessage('blah blah '), False) The sample you mentioned (threadedclient) is a client, not a server. Apparently, the problem is at logger.info("Managing websocket %s" % format_addresses(websocket))
websocket.opened()
with self.lock:
fd = websocket.sock.fileno()
self.websockets[fd] = websocket
self.poller.register(fd) Avishay |
I have this problem too. Client throws because websocket data from
|
Is there an update on this? I'm having the same problem |
I started investigating and the problem appears to be with "on_end_request " hook provided by cherrypy. The documentation states that it is called when the conversation is over and all data has been written to the client, but this doesn't appear to be true since it's getting called before the response is being sent to the client. |
I came up with a temporary workaround by having the WSGIGateway delay closing the response until it sends the headers. This seemed to fix the issue, I'll talk with the cherrypy team about a proper fix. |
Hi! I too can't send messages from the server on connection opening, but I'm having a slightly different error, so I thought I should share:
Here's my server class:
|
Any news? |
Your error looks to be the same issue I encountered. I submitted a bug and proposed fix last month, but the Cherrypy team hasn't responded to either. You can use my proposed fix below to resolve your issue |
@Lawouach could you please bump @ronin8600's patch to CherryPy? I've tried it, it's working. This issue is a nasty one, really ruins the whole websocket thing for me. |
Gang:
I'm working with the extended chat example (works great out of the box), and trying to send a message from the server to the client when the web socket is initially opened:
However, this causes the web socket to be terminated. I've also tried publishing the message:
... which doesn't terminate the web socket, but doesn't send the message to the newly-connected client either (I assume this is because the broadcast is going out before the handler has been transferred to the WebSocketPlugin pool).
I'm looking to use web sockets for purely one-way publishing of a data feed from server to client(s), so this seems like a pretty basic use-case. What am I missing?
Thanks in advance,
Tim
The text was updated successfully, but these errors were encountered: