#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
#define ERR(a) fprintf(stderr, "Error: %s\n", a)
int main()
{
int client;
struct addrinfo hints, *server_info;
uint32_t n, fib_n;
memset((void *) &hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo("127.0.0.1", "4000", &hints, &server_info);
client = socket(server_info->ai_family, server_info->ai_socktype, server_info->ai_protocol);
if (client < 0)
{
ERR("could not get a socket!");
return -1;
}
if (connect(client, server_info->ai_addr, server_info->ai_addrlen) < 0)
{
ERR("could not connect to the server!");
return -1;
}
printf("Connected to the server!\n");
do
{
printf("Please enter a number: ");
scanf("%d", &n);
send(client, (void *) &n, sizeof(uint32_t), 0);
recv(client, (void *) &fib_n, sizeof(uint32_t), 0);
printf("The server says that fib(%d) = %d\n", n, fib_n);
} while(n > 0);
close(client);
return 0;
}