Skip to content
Snippets Groups Projects
Commit cb62f4a4 authored by steffeno's avatar steffeno
Browse files

maxServer fix

parent 7a37a378
No related branches found
No related tags found
No related merge requests found
all: client server
client: client.c
gcc client.c -o client
gcc -g client.c -o client
server: server.c
gcc server.c -o server
gcc -g server.c -o server
......@@ -61,20 +61,18 @@ int main(int argc, char *argv[]) {
puts("inserisci numero");
char number[16];
fgets(number, sizeof(number), stdin);
number[strcspn(buffer, "\n")] = '\0';
puts("about to write number");
number[strcspn(number, "\n")] = '\0';
write(simpleSocket, number, strlen(number));
puts("number sent");
memset(buffer, '\0', sizeof(buffer));
returnStatus = read(simpleSocket, buffer, sizeof(buffer));
if ( returnStatus > 0 ) {
printf("%d: %s\n", returnStatus, buffer);
printf("max: %s\n", buffer);
// printf("%d: %s\n", returnStatus, buffer);
} else {
fprintf(stderr, "Return Status = %d \n", returnStatus);
}
printf("max: %s\n", buffer);
close(simpleSocket);
}
......
......@@ -95,9 +95,7 @@ int main(int argc, char *argv[]) {
puts("connection accepted");
char buffer[16] = { 0 };
puts("about to read");
int returnStatus = read(simpleChildSocket, buffer, sizeof(buffer));
puts("read");
if ( returnStatus > 0 ) {
printf("%d: read %s\n", returnStatus, buffer);
} else {
......@@ -105,12 +103,15 @@ int main(int argc, char *argv[]) {
}
long num;
puts("LLSKDJF");
int res = parse_long(buffer, &num);
if (res < 0) {
// FIXME: handling error this way makes client's life harder
puts("invalid number");
continue;
}
if (num > max) {
max = num;
}
char buf[16];
snprintf(buf, sizeof(buf), "%ld", max);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment