Tutorial: Chat server

Let's learn how to get a simple chat server up and running without writing any code. The next chapter, ‘Plugins’, will dive deeper into how to create a plugin.

Starting YAKjs

Open a shell (terminal window) and start YAKjs with:

$ yakjs

Now, YAKjs is running and uses this ports:

PortProtocolDescription

8790

HTTP

Provides the user interface and the REST API.

9020

WS

A chat WebSocket endpoint

The user interface

Start your favorite browser and open the YKAjs user interface at http://localhost:8790

The first page Instances provides a list of configured WebSocket server instances. Make sure that the chat service is started.

Chat clients

To test if the chat server is working, let's us the websocket.org echo client

UI instance list

We can connect to our local WebSocket chat instance on ws://localhost:9020. Now you can write a text and send it.

Plugins make it work

The chat instance uses two plugins, the echo and broadcast plugin. The magic happens there.

YAKjs WebSocket chat overview

echo

The echo plugin sends back the received message. The send text is displayed in the log area. If you don't like to see your own messages, open the YAKjs user interface and configure the chat instance and disable the echo plugin. Stop and start the chat instance so that your configuration will apply. When you stop an instance all connected clients will be disconnected. You can see a DISCONNECTED message in the log.

broadcast

The broadcast plugin sends the received message to every connected client, but not back to the sender. Let's open a second websocket.org echo client and also connect it to ws://localhost:9020, now we have two clients and the chat can start.

The broadcast plugin is great for every publish to all clients use case.

Complete!

Congrats! We have our chat system up and running. Keep in mind that YAKjs is a tool for prototyping, simulation and testing. It is not designed to be used in a production environment, even if it is very stable and reliable.

With this tutorial you have learned:

  • starting YAKjs
  • chat is a WebSocket instance running on port 9020
  • use the websocket.org echo client as a simple client to connect
  • how to chat with yourself
  • chat uses two plugins echo and broadcast
  • stopping an instance will disconnect all clients