2 ![dyad.c](https://cloud.githubusercontent.com/assets/3920290/3942261/5de470e4-255d-11e4-95a9-5f97fa9f3a57.png)
5 Dyad.c is an asynchronous networking library which aims to be lightweight,
6 portable and easy to use. It can be used both to create small standalone
7 servers and to provide network support to existing projects.
10 The [dyad.c](src/dyad.c?raw=1) and [dyad.h](src/dyad.h?raw=1) files can be
11 dropped into an existing project; if you're using Windows you will also have to
14 An overview of the API can be found at [doc/api.md](doc/api.md).
16 Usage examples can be found at [example/](example/).
19 A simple server which listens on port 8000 and echoes whatever is sent to it:
24 static void onData(dyad_Event *e) {
25 dyad_write(e->stream, e->data, e->size);
28 static void onAccept(dyad_Event *e) {
29 dyad_addListener(e->remote, DYAD_EVENT_DATA, onData, NULL);
30 dyad_writef(e->remote, "Echo server\r\n");
36 dyad_Stream *serv = dyad_newStream();
37 dyad_addListener(serv, DYAD_EVENT_ACCEPT, onAccept, NULL);
38 dyad_listen(serv, 8000);
40 while (dyad_getStreamCount() > 0) {
50 A simple example program which connects to a
51 [daytime](http://en.wikipedia.org/wiki/Daytime_Protocol) server and prints the
57 static void onConnect(dyad_Event *e) {
58 printf("connected: %s\n", e->msg);
61 static void onData(dyad_Event *e) {
62 printf("%s", e->data);
68 dyad_Stream *s = dyad_newStream();
69 dyad_addListener(s, DYAD_EVENT_CONNECT, onConnect, NULL);
70 dyad_addListener(s, DYAD_EVENT_DATA, onData, NULL);
71 dyad_connect(s, "time-nw.nist.gov", 13);
73 while (dyad_getStreamCount() > 0) {
84 This library is free software; you can redistribute it and/or modify it under
85 the terms of the MIT license. See [LICENSE](LICENSE) for details.