Chat demonstration. (fork of computionist's noth-chat)  (


# Overview

This is a 2-3 hour group exercise for learning basics of concurrency
primitives in Haskell, multicast network protocols, and interacting in
real time with people on a shared network.

Contributions to this project are welcome under the guidelines of
[Coraline's Contributor Covenant](

The goals are to create a local network multicast system that:

1. Handles choosing a unique name
2. Announces this name
3. Receives other name announcements
4. Broadcasts messages to the network
5. Prints received messages from the network

Topics covered will include:

1. Protocol design
2. Command String Parsing
3. Multicast Sockets
4. Addressing and Ports
5. Asynchronous execution

The emphasis will be on writitng as much in pure code as possible, and
then using I/O as a minimal wrapper for the pure code.

# Introduction

## Darcs

Since the source is distributed as a Darcs repository, make sure you
have darcs installed. Darcs can be installed from cabal:

    cabal install darcs

## Cabal

This is a Cabal package. It can be built in place using a Cabal
sandbox. These instructions will work if you have at least Cabal 1.18
installed, which should come with any recent Haskell Platform. So,
after unpacking the source for this project, change to the directory
with this README and run the following:

    cabal sandbox init
    cabal install

This will put the executable in `.cabal-sandbox/bin/noth-chat`.

# Lesson 1 - Hello PDU, Covering Network.Chat.PDU

This first lesson is about designing a basic `Hello` protocol. This
`Hello` protocol defines a single "Protocol Data Unit" (a "PDU"). This
Hello PDU contains a name, and is sent over a multicast socket so that
every system on the local network sees it.

## PDU Header

Protocols consist of nested layers of data. These correspond to
processing functions in implementations, and the functions are chained
just like the nested data is chained. Each function in the chain
receives everything in a message from its header to the end, and
decides what to do with following layers based on its own layer.

Our protocol has a simple envelope. It contains a version number and a
length of the payload. The header is processed by the Header type. It
currently only has a single version, Version 1.

## Hello PDU

The "Hello PDU" immediately follows the "PDU Header". It's encoded as
two UTF-8 strings. The first is the word "HELLO", and the second is a
name. Strings are encoded with a length prefix so that the functions
know exactly how many bytes to read from the stream.