-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9fd88b
Showing
7 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# SimpleChat | ||
|
||
A very simple socket-based chat application built in Ruby. | ||
|
||
## Design | ||
|
||
The program design loosely follows a [publish/subscribe pattern](http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_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. | ||
|
||
## Usage | ||
|
||
Two binary files are provided: one to run the chat server, and one to run a client session. | ||
|
||
### Server | ||
|
||
To run the server, execute `bin/server` from the app's root directory. | ||
|
||
```bash | ||
$ bin/server | ||
|
||
Simple Chat server is running. | ||
Listening for connections on HOSTNAME:PORT... | ||
``` | ||
|
||
It also accepts options to specify the **hostname** and **port**. | ||
|
||
```bash | ||
$ bin/server -h my_computer.local -p 7777 | ||
|
||
Simple Chat server is running. | ||
Listening for connections on my_computer.local:7777... | ||
``` | ||
|
||
### Client | ||
|
||
To start a client session, execute `bin/client` from the app's root directory. | ||
|
||
```bash | ||
$ 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. | ||
|
||
```bash | ||
$ 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path('../../config.rb', __FILE__) | ||
|
||
# Run your client code from here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path('../../config.rb', __FILE__) | ||
|
||
# Run your server code from here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'socket' | ||
|
||
require File.expand_path('../lib/helpers.rb', __FILE__) | ||
require File.expand_path('../lib/client.rb', __FILE__) | ||
require File.expand_path('../lib/server.rb', __FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Chat client code goes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Any helper code goes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Chat server code goes here |