A simple WebSocket chat server written in Haskell. Used in the JavaScript course from Devalot: https://code.devalot.com/training/webdev
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Peter J. Jones ac28f0a8a4
Reduce boilerplate, update dependencies, release 0.1.0.1
pirms 4 mēnešiem
examples Add example JavaScript app and code snippets to the README pirms 10 mēnešiem
src Reduce boilerplate, update dependencies, release 0.1.0.1 pirms 4 mēnešiem
.gitignore Initial import pirms 10 mēnešiem
CHANGES.md Initial import pirms 10 mēnešiem
LICENSE Reduce boilerplate, update dependencies, release 0.1.0.1 pirms 4 mēnešiem
README.md Fix table formatting in the README pirms 10 mēnešiem
Setup.hs Initial import pirms 10 mēnešiem
default.nix Initial import pirms 10 mēnešiem
wschat.cabal Reduce boilerplate, update dependencies, release 0.1.0.1 pirms 4 mēnešiem
wschat.nix Reduce boilerplate, update dependencies, release 0.1.0.1 pirms 4 mēnešiem

README.md

A Simple WebSocket Chat Server

This package includes a single executable: wschat. It’s an extremely simple chat server using WebSockets.

The primary goal of this package is to provide a WebSocket server for students who are learning JavaScript so they have a real server to experiment with.

Connecting from JavaScript

Before connecting you will need two pieces of information: the server’s host name and an access code. For this example we’ll assume the following information:

Needed Information Example Value
hostname example.com
access code abc123

Now we can construct a URL and open a connection:

const socket = new WebSocket("wss://example.com/abc123");

NOTE: if your server doesn’t support SSL/TLS you will have to replace wss:// with ws://.

All chat messages that are sent and received are JSON encoded objects that look like this:

{
  "sender": "name of message sender",
  "content": "the content of the message"
}

Here’s an example of sending a message to the server:

const message = {
  sender: "Alice",
  content: "Hello!"
};

socket.send(JSON.stringify(message));

A complete example using web components can be found in the examples directory.