A very simple socket-based chat application built in Ruby.
The program design loosely follows a publish/subscribe pattern whereby one or more clients establish a connection to a central server. Upon establishing a connection, clients can send messages to the server, which are then broadcast to any and all connected clients listening on the same channel.
Something like what is illustrated in this beautiful diagram:
Got it? Good.
Two binary files are provided: one to run the chat server, and one to run a client session.
To run the server, execute bin/server
from the app's root directory.
$ bin/server
Simple Chat server is running.
Listening for connections on HOSTNAME:PORT...
It also accepts options to specify the hostname and port.
$ bin/server -h my_computer.local -p 7777
Simple Chat server is running.
Listening for connections on my_computer.local:7777...
To start a client session, execute bin/client
from the app's root directory.
$ bin/client
Welcome! There are N people online.
In addition to specifying the hostname and port to connect to, you can also provide the client with a name, which will be used to identify the client.
$ bin/client -n my name -h my_computer.local -p 7777
Welcome! There are N people online.
Thus, when another client connects to the same server, messages are prefixed with the sender's name.