| ... | ... |
@@ -31,16 +31,16 @@ of the things explored: |
| 31 | 31 |
[Client-server]: https://en.wikipedia.org/wiki/Client-server |
| 32 | 32 |
[Online chat]: https://en.wikipedia.org/wiki/Online_chat |
| 33 | 33 |
[Terminal user interface]: https://en.wikipedia.org/wiki/Terminal_user_interface |
| 34 |
-[POSIX 2004]: https://pubs.opengroup.org/onlinepubs/009695399/toc.htm |
|
| 34 |
+[POSIX 2004]: https://pubs.opengroup.org/onlinepubs/9699919799/toc.htm |
|
| 35 | 35 |
[C99]: https://en.wikipedia.org/wiki/C99 |
| 36 | 36 |
[`errno.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html |
| 37 | 37 |
[`stdarg.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdarg.h.html |
| 38 |
-[`getopt`]: https://pubs.opengroup.org/onlinepubs/009695399/functions/getopt.html |
|
| 38 |
+[`getopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html |
|
| 39 | 39 |
[`sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html |
| 40 | 40 |
[`sys/select.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_select.h.html |
| 41 |
-[`netdb.h`]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html |
|
| 42 |
-[`search.h`]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/search.h.html |
|
| 43 |
-[`termios.h`]: https://pubs.opengroup.org/onlinepubs/007904975/basedefs/termios.h.html |
|
| 41 |
+[`netdb.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html |
|
| 42 |
+[`search.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/search.h.html |
|
| 43 |
+[`termios.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html |
|
| 44 | 44 |
[Data-centered design]: https://lwn.net/Articles/193245/ |
| 45 | 45 |
[Coupling]: https://en.wikipedia.org/wiki/Coupling_(computer_programming) |
| 46 | 46 |
[Scope]: https://en.wikipedia.org/wiki/Scope_(computer_science) |
| ... | ... |
@@ -2,6 +2,99 @@ |
| 2 | 2 |
|
| 3 | 3 |
Chat with unlimited number of peers through a variety of sockets. |
| 4 | 4 |
|
| 5 |
+`sockchat` is a simple [client-server][] [online chat][] application with a |
|
| 6 |
+[terminal user interface][]. Both the client and the server are bundled into |
|
| 7 |
+the same executable. One of the main goals is to support a broad variety of |
|
| 8 |
+communication protocols, see [usage](#usage). |
|
| 9 |
+ |
|
| 10 |
+`sockchat` was written for educational purposes under a fairly short time and |
|
| 11 |
+consists of less than 600 lines of portable [POSIX 2004][], [C99][] code. Some |
|
| 12 |
+of the things explored: |
|
| 13 |
+ |
|
| 14 |
+- Standard C: |
|
| 15 |
+ - [`errno.h`][], thorough error handling. |
|
| 16 |
+ - [`stdarg.h`][], useful and convenient logging and error reporting. |
|
| 17 |
+- POSIX: |
|
| 18 |
+ - [`getopt`][], robust command line interface. |
|
| 19 |
+ - [`sys/socket.h`][], Berkley sockets. |
|
| 20 |
+ - [`sys/select.h`][], local and network I/O multiplexing. |
|
| 21 |
+ - [`netdb.h`][], network protocols. |
|
| 22 |
+ - [`search.h`][], data structures. |
|
| 23 |
+ - [`termios.h`][], simple text-based user interface. |
|
| 24 |
+- Software design: |
|
| 25 |
+ - [Data-centered design][]. |
|
| 26 |
+ - Low [coupling][]. |
|
| 27 |
+ - Narrow variable [scope][]s. |
|
| 28 |
+ - 79 [characters per line][], consistent breaking strategies. |
|
| 29 |
+ - Horrible, horrible [macros][]. |
|
| 30 |
+ |
|
| 31 |
+[Client-server]: https://en.wikipedia.org/wiki/Client-server |
|
| 32 |
+[Online chat]: https://en.wikipedia.org/wiki/Online_chat |
|
| 33 |
+[Terminal user interface]: https://en.wikipedia.org/wiki/Terminal_user_interface |
|
| 34 |
+[POSIX 2004]: https://pubs.opengroup.org/onlinepubs/009695399/toc.htm |
|
| 35 |
+[C99]: https://en.wikipedia.org/wiki/C99 |
|
| 36 |
+[`errno.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html |
|
| 37 |
+[`stdarg.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdarg.h.html |
|
| 38 |
+[`getopt`]: https://pubs.opengroup.org/onlinepubs/009695399/functions/getopt.html |
|
| 39 |
+[`sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html |
|
| 40 |
+[`sys/select.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_select.h.html |
|
| 41 |
+[`netdb.h`]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html |
|
| 42 |
+[`search.h`]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/search.h.html |
|
| 43 |
+[`termios.h`]: https://pubs.opengroup.org/onlinepubs/007904975/basedefs/termios.h.html |
|
| 44 |
+[Data-centered design]: https://lwn.net/Articles/193245/ |
|
| 45 |
+[Coupling]: https://en.wikipedia.org/wiki/Coupling_(computer_programming) |
|
| 46 |
+[Scope]: https://en.wikipedia.org/wiki/Scope_(computer_science) |
|
| 47 |
+[Characters per line]: https://en.wikipedia.org/wiki/Characters_per_line |
|
| 48 |
+[Macros]: https://en.wikipedia.org/wiki/C_preprocessor |
|
| 49 |
+ |
|
| 50 |
+## Usage |
|
| 51 |
+ |
|
| 52 |
+See also [examples](#examples). |
|
| 53 |
+ |
|
| 54 |
+`sockchat --help`: |
|
| 55 |
+ |
|
| 56 |
+``` |
|
| 57 |
+sockchat 1.0 - Chat with unlimited number of peers through a variety of sockets |
|
| 58 |
+ |
|
| 59 |
+Usage: |
|
| 60 |
+ sockchat (server|client) [options] |
|
| 61 |
+ sockchat -h|--help |
|
| 62 |
+ sockchat --version |
|
| 63 |
+ |
|
| 64 |
+Options: |
|
| 65 |
+ -f <family> [default: INET] |
|
| 66 |
+ -t <socktype> [default: DGRAM] |
|
| 67 |
+ -p <protocol> [default: 0] |
|
| 68 |
+ -n <node> [default: ] |
|
| 69 |
+ -s <service> [default: 3200] |
|
| 70 |
+ |
|
| 71 |
+Recognized values for <family>: |
|
| 72 |
+ UNSPEC |
|
| 73 |
+ UNIX |
|
| 74 |
+ LOCAL |
|
| 75 |
+ INET |
|
| 76 |
+ INET6 |
|
| 77 |
+ PACKET |
|
| 78 |
+ |
|
| 79 |
+Recognized values for <socktype>: |
|
| 80 |
+ 0 |
|
| 81 |
+ STREAM |
|
| 82 |
+ DGRAM |
|
| 83 |
+ SEQPACKET |
|
| 84 |
+ RAW |
|
| 85 |
+ RDM |
|
| 86 |
+ PACKET |
|
| 87 |
+ |
|
| 88 |
+Recognized values for <protocol>: |
|
| 89 |
+ 0 |
|
| 90 |
+ IP |
|
| 91 |
+ TCP |
|
| 92 |
+ UDP |
|
| 93 |
+ UDPLITE |
|
| 94 |
+ SCTP |
|
| 95 |
+ ICMP |
|
| 96 |
+``` |
|
| 97 |
+ |
|
| 5 | 98 |
## Building |
| 6 | 99 |
|
| 7 | 100 |
A simple [`Makefile`](Makefile) is provided, build with |
| ... | ... |
@@ -12,13 +105,63 @@ make |
| 12 | 105 |
|
| 13 | 106 |
## Installation |
| 14 | 107 |
|
| 15 |
-The produced executable is self-contained and can be run from wherever, but can |
|
| 16 |
-be installed with |
|
| 108 |
+The produced executable can be run from anywhere. It can however be installed |
|
| 109 |
+with |
|
| 17 | 110 |
|
| 18 | 111 |
```sh |
| 19 | 112 |
make install |
| 20 | 113 |
``` |
| 21 | 114 |
|
| 115 |
+## Implementation notes |
|
| 116 |
+ |
|
| 117 |
+## Examples |
|
| 118 |
+ |
|
| 119 |
+<table> |
|
| 120 |
+<tr> |
|
| 121 |
+<th>Server</th> |
|
| 122 |
+<th>Client Alice</th> |
|
| 123 |
+<th>Client Bob</th> |
|
| 124 |
+</tr> |
|
| 125 |
+<tr> |
|
| 126 |
+<td style="vertical-align: top;"> |
|
| 127 |
+<pre> |
|
| 128 |
+$ sockchat server |
|
| 129 |
+Info: Using buffer size 255 |
|
| 130 |
+Info: Trying to bind... |
|
| 131 |
+Info: Succeeded to bind |
|
| 132 |
+Info: Client '[192.168.0.3:50453] Alice' joined |
|
| 133 |
+Info: Client '[192.168.0.4:48678] Bob' joined |
|
| 134 |
+Info: Client '[192.168.0.3:50453] Alice' sent 11 bytes |
|
| 135 |
+Info: Client '[192.168.0.4:48678] Bob' sent 13 bytes |
|
| 136 |
+Info: Client '[192.168.0.3:50453] Alice' left |
|
| 137 |
+Info: Client '[192.168.0.4:48678] Bob' left |
|
| 138 |
+</pre> |
|
| 139 |
+</td> |
|
| 140 |
+<td style="vertical-align: top;"> |
|
| 141 |
+<pre> |
|
| 142 |
+$ sockchat client |
|
| 143 |
+Info: Using buffer size 255 |
|
| 144 |
+Info: Trying to connect... |
|
| 145 |
+Info: Succeeded to connect |
|
| 146 |
+User name: Alice |
|
| 147 |
+[192.168.0.3:50453] Alice: Hello Bob! |
|
| 148 |
+[192.168.0.4:48678] Bob: Hello Alice! |
|
| 149 |
+</pre> |
|
| 150 |
+</td> |
|
| 151 |
+<td style="vertical-align: top;"> |
|
| 152 |
+<pre> |
|
| 153 |
+$ sockchat client |
|
| 154 |
+Info: Using buffer size 255 |
|
| 155 |
+Info: Trying to connect... |
|
| 156 |
+Info: Succeeded to connect |
|
| 157 |
+User name: Bob |
|
| 158 |
+[192.168.0.3:50453] Alice: Hello Bob! |
|
| 159 |
+[192.168.0.4:48678] Bob: Hello Alice! |
|
| 160 |
+</pre> |
|
| 161 |
+</td> |
|
| 162 |
+</tr> |
|
| 163 |
+</table> |
|
| 164 |
+ |
|
| 22 | 165 |
## License |
| 23 | 166 |
|
| 24 | 167 |
Licensed under the [ISC License][], see the [`LICENSE`](LICENSE) file. |
| ... | ... |
@@ -2,6 +2,23 @@ |
| 2 | 2 |
|
| 3 | 3 |
Chat with unlimited number of peers through a variety of sockets. |
| 4 | 4 |
|
| 5 |
+## Building |
|
| 6 |
+ |
|
| 7 |
+A simple [`Makefile`](Makefile) is provided, build with |
|
| 8 |
+ |
|
| 9 |
+```sh |
|
| 10 |
+make |
|
| 11 |
+``` |
|
| 12 |
+ |
|
| 13 |
+## Installation |
|
| 14 |
+ |
|
| 15 |
+The produced executable is self-contained and can be run from wherever, but can |
|
| 16 |
+be installed with |
|
| 17 |
+ |
|
| 18 |
+```sh |
|
| 19 |
+make install |
|
| 20 |
+``` |
|
| 21 |
+ |
|
| 5 | 22 |
## License |
| 6 | 23 |
|
| 7 | 24 |
Licensed under the [ISC License][], see the [`LICENSE`](LICENSE) file. |