Old stuff/ecole_etude_fac_de_pau/licence_3/projet_commun_se/backup12/client.c
(Deskargatu)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <rpc/xdr.h>
#include "include/tcp.h"
#include "include/global.h"
#include "include/demandes.h"
#include "include/sockets.h"
int main(int argc, char** argv)
{
sock = con_tcp(4000,"localhost");
// printf("Client %d\n",sock);
XDR data;
data.x_op=XDR_ENCODE;
xdrrec_create(&data, 0, 0, (void*)sock, (void*)read_tcp, (void*)write_tcp);
demande_item dem;
bzero(&dem,sizeof(demande_item));
dem.op=1;
dem.demi_brune=1;
dem.peinte_blonde=1;
if (!xdr_demande(&data,&dem)) { perror("clients.c xdr_demande"); exit(-1); }
if (!xdrrec_endofrecord(&data, TRUE)) { perror("send eof"); exit(-1); }
perror("OK !!");
printf("ENVOIE de la demande\n");
xdr_destroy(&data);
fd_set sockets;
int nb = 0;
nb_clients = &nb;
while(1)
{
select_client(&sockets);
if (FD_ISSET(sock,&sockets))
{
XDR reception;
retour_item ret;
reception.x_op=XDR_DECODE;
printf("Socket de lecture %d\n",sock);
xdrrec_create(&reception, 0, 0, (void*)sock, (void*)read_tcp, (void*)write_tcp);
if (!xdrrec_skiprecord(&data)) { perror("client.c skiprecord"); exit(-1); }
if (!xdr_retour(&reception,&ret)) { perror("clients.c xdr_demande"); exit(-1); }
printf("Recu le retour %d %d %d %d\n",ret.demi_blonde, ret.demi_brune, ret.peinte_blonde, ret.peinte_brune);
}
}
close(sock);
return 0;
}