diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-09 09:56:49 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-09 09:57:38 +0100 |
commit | f231e6db05ac4b09fa6aad0d17216f6ac21380d4 (patch) | |
tree | b95d819cc7b2fc7836803ea2dacd04025a8d7225 | |
parent | 0e7508ba4366a6f4e6b2f0ac5cc520a2f37fb7d6 (diff) | |
download | wbs-f231e6db05ac4b09fa6aad0d17216f6ac21380d4.tar.gz wbs-f231e6db05ac4b09fa6aad0d17216f6ac21380d4.tar.bz2 wbs-f231e6db05ac4b09fa6aad0d17216f6ac21380d4.zip |
pd_server: Start a new round after one has finished
So that 2 new clients can connect.
-rw-r--r-- | pd_server.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/pd_server.c b/pd_server.c index 7c5a01f..b8ff6f0 100644 --- a/pd_server.c +++ b/pd_server.c @@ -59,33 +59,36 @@ main(int argc, char *argv[]) } listen(sock, 2); - for (i = 0; i < 2; ++i) { - player[i] = accept(sock, NULL, NULL); - } - for (i = 0; i < rounds; ++i) { - char a, b; - read(player[0], &a, 1); - read(player[1], &b, 1); - - if (a != 'c' && a != 'd') { - printf("a sent incorrect char: %c\n", a); - continue; - } - if (b != 'c' && b != 'd') { - printf("b sent incorrect char: %c\n", b); - continue; + for (;;) { + for (i = 0; i < 2; ++i) { + player[i] = accept(sock, NULL, NULL); } + for (i = 0; i < rounds; ++i) { + char a, b; + read(player[0], &a, 1); + read(player[1], &b, 1); - a_payment += pay(a, b); - b_payment += pay(b, a); + if (a != 'c' && a != 'd') { + printf("a sent incorrect char: %c\n", a); + continue; + } + if (b != 'c' && b != 'd') { + printf("b sent incorrect char: %c\n", b); + continue; + } - printf("A [%c]: %d Euro\tB [%c]: %d Euro\t\t\tA: %d\tB: %d\n", - a, pay(a, b), b, pay(b, a), a_payment, b_payment); + a_payment += pay(a, b); + b_payment += pay(b, a); - write(player[0], &b, 1); - write(player[1], &a, 1); + printf("A [%c]: %d Euro\tB [%c]: %d Euro\t\t\t" + "A: %d\tB: %d\n", + a, pay(a,b), b, pay(b,a), a_payment, b_payment); + + write(player[0], &b, 1); + write(player[1], &a, 1); + } + close(player[0]); + close(player[1]); } - close(player[0]); - close(player[1]); close(sock); } |