A CHICKEN Scheme module for Awful web framework that provides Server-Sent Events according to http://dev.w3.org/html5/eventsource/ specification.
Requires awful, spiffy and intarweb eggs.
Note: if you need a full-duplex communication channel over a single TCP connection, please consider using Websockets.
To see the magic happening with SSE, try the examples.
Define two awful pages:
- The "client page" that is accessed via path and presents contents. It is a "normal" awful page and should be used as the link presented to the client;
Note that sse-proc should keep the connection open, so usually it is an infinite loop. In order to avoid CPU consumption this loop should sleep some seconds and, for that, be sure to use SRFI-18 thread-sleep! instead of blocking sleep procedure.
- send-sse-data data #!key event idprocedure
Send data from server to the client using the current HTTP connection. event and id keywords are used to set the data type and unique id respectively. When there is no event field set, the client understands the data type is "message". id is also optional.
- send-sse-retry millisecondsprocedure
Send the "retry: milliseconds" message to define the reconnection timeout for the client.
Run with awful example1.scm. On web browser open http://localhost:8080/client and watch the new time coming each second from the server.
SSE and Ajax
Run with awful example2.scm. Open two web browsers and point both to http://localhost:8080/client. Try clicking on the blue and the red div and see them changing their boolean values on *both* browsers.
Do you have any useful SSE example? Please share it here!
- 0.3 Ported to Chicken 5
- 0.2 Added tests
- 0.1 Initial version
Copyright (c) 2014, Arthur Maciel; 2020, Daniel Ziltener All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.