Next: Echo Server, Previous: Hello World Web Server, Up: Communications Samples [Index]
A server reading what concurrent clients are transmitting (it makes use of one ‘dispatch’ controller):
void dc(dispatch p, file i) { integer c, s; c = f_pick(i); if (c ^ -1) { s = f_stored(i); o_form("%c\n", c); while (s) { c = f_pick(i); o_form("%c\n", c); s -= 1; } } if (c == -1) { w_resign(p, i); } } void pc(dispatch p, file f) { file i, o; accept(i, o, f, 0); w_watch(p, i, dc, p, i); } integer main(void) { dispatch p; file f; tcpip_listen(f, 40000, 0); w_watch(p, f, pc, p, f); w_press(p); return 0; }
See The Control Library.