luixal / sse

Server-Sent Events Example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server-Sent Events Examples

What is this?

Server-Sent Events are a way of sending information from a server to its clients using just HTTP. Also, it has no dependencies for clients as all major browsers support it out of the box.

This repo contains some code projects showing example of how to work with it:

How do I run this?

You need to use at least two pieces for the example to work: a server and a client.

Server

First, you need to run the server, just get into the sse-server directory and install its dependencies:

npm i

then, just run the server:

npm start

you should see something like this:

SSE Example Server listening on 5001

that means that the server is running and listening for connections.

Clients

There are two similar clients that only differ in the front tooling used in each one. You just need to open in your brower the index.html located in any of the client directories: sse-client/vue or sse-client/jquery and you should start seeing message.

Where do this messages come from?

Every 5 seconds, the server fetches a joke from ChuckNorris API and sends that joke as an SSE message to the clients.

Also, in the terminal you have opened your server, you can type some text and, when hitting enter, that text will be sent

About

Server-Sent Events Example

License:GNU General Public License v3.0


Languages

Language:HTML 72.1%Language:JavaScript 27.9%