HTML and CSS Reference
In-Depth Information
Listing 4.7. Add a chat message (server code)
You've created a simple interface and a way to add new chat messages—now at last you're
ready to start using SSE. What you need next is a way to get the chat messages of other
users to appear in your browser as they're entered by your fellow chatters. This is the sort
of task SSE is designed for.
Step 7: Build an SSE stream at the server
The following snippet shows an excerpt from an SSE event stream like the one you're
about to create. It's all plain text and should be served with the MIME type text/event-
stream (typically, because you're generating the event stream dynamically, you'll set the
MIME type in your server-side code). A sample of the event stream you'll be generating is
shown here:
Search WWH ::




Custom Search