Send information to a client via websocket

7 views
Skip to first unread message

Anders Persson

unread,
May 2, 2020, 12:57:21 PM5/2/20
to Eiffel Web Framework
Hi

I would like to send information to a client via a Websocket. So far I have  only been able to do that when a client contact the server, i.e. the server is able to respond via the socket connection that the client has created.

If the client keep the socket connection, which it does in my implementation, I would like to be able to send information to the client due to server side events, e.g. something happens at the server and it would like to send information to the client. Then I assume that I would need to have a reference to the socket in the server. I also assume that this reference would need to be declared as separate.

My problem is that I can not find where a new socket connection is created in the server. Can you direct me to that point in the code and maybe describe how I can refer to that web_socket/web_socket_handler or any other separate object that I can save for future use, just in case the server want to send something to the client.

My current solution is to let the client poll for information which will both be too time consuming and will use a lot of  memory  at the server.

Regards

Anders

Anders Persson

unread,
May 16, 2020, 11:43:11 AM5/16/20
to Eiffel Web Framework
Hi 

I have now tested  a solution where i keep a reference to the  object of type HTTPD_REQUEST_HANDLER. Then I am able to refer via that to the socket. The problem with this is that when the socket connection is created the safe_execute feature in HTTPD_REQUEST_HANDLER_I is called and that never ends. It just listen to the socket and when a request arrives it calls a callback and the server answers the request. Then waits for the next request from the client. If I try to connect to the SCOOP process executing safe_execute it will never answer. 

To create a socket-proxy or a server that by an event would like to send something to the client I think that writing to the  socket must be in a separate process that not only the above safe_execute can write to. 

Any proposal of how to implement it?

Anders
Reply all
Reply to author
Forward
0 new messages