From f231e6db05ac4b09fa6aad0d17216f6ac21380d4 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 9 Nov 2012 09:56:49 +0100 Subject: pd_server: Start a new round after one has finished So that 2 new clients can connect. --- pd_server.c | 49 ++++++++++++++++++++++++++----------------------- 1 file 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); } -- cgit