Come per il server ti posto il client:
codice:
/*funzione del thread di scrittura*/
void * thr_writer(void * argv)
{
buffer = (msg_t *) malloc(sizeof(msg_t));
buff = calloc(256, sizeof(char));
while(go)
{
/* a seconda del tipo di messaggio desiderato strutturo buffer*/
//invio il messaggio
buff = msgclient_pack(buffer->type, buffer->msg, buffer->sender, buffer->receiver);
write(sock, buff, 256*sizeof(buff));
buffer = (msg_t *) malloc(sizeof(msg_t));
}
return NULL;
}
/*funzione del thread di lettura*/
void * thr_reader(void * argv)
{
buffer = (msg_t *) malloc(sizeof(msg_t));
buff_rd = calloc (256, sizeof(char));
while(go)
{
rv_byte = recv(sock, buff_rd, 256*sizeof(buff_rd), 0);
if (rv_byte != 0 && rv_byte!= -1)
{
buffer = msg_unpack(buff_rd);
if (buffer->type == MSG_BRDCAST)
{
/* printf contenuto messaggio */
}
else if (buffer->type == MSG_SINGLE)
{
/* printf contenuto messaggio */
}
else if (buffer->type == MSG_LIST)
{
/* printf lista utenti connessi */
}
}
buffer = (msg_t *) malloc(sizeof(msg_t));
}
return NULL;
}
Ho provato a stampare il contenuto dopo la recv: quando, dopo il login, invio, ad esempio, un messaggio di list, mi stampa appunto la richiesta inviata dal client; se ripeto l'operazione non stampa nulla. Aggiungo che prima avevo anche provato ad utilizzare la read al posto della recv.