I get which client send message to server with this code;
recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen));
printf("Received packet from %s:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
And I can send message to this client with this code;
sendto(s, "data", recv_len, 0, (struct sockaddr*) &si_other, slen);
But I want to send this message (“data”) to all clients , not just one client. How can I do that ?
You keep track of the connections you have accepted from clients in a list, and when you want to send a message to everyone, you iterate that list with a loop and you send the desired message to each one, individually.