I have written a TCP server application in C code that can handle multiple clients connections at the same time. When the server receive data from one client, all the clients should receive it. I've used select() in order to create the connection between server and multiple clients but i don't know how to do that all the clients receive the same data at the same time and each of them be able to send data to the server.
read_option(fd) is my function used in the application
while(1)
{
select (nfds+1, &readfds, NULL, NULL, &tv);
if (FD_ISSET (sd, &readfds))
{
len = sizeof (from);
bzero (&from, sizeof (from));
client = accept (sd, (struct sockaddr *) &from, &len);
if (client < 0)
{
continue;
}
if (nfds < client)
nfds = client;
FD_SET (client, &actfds);
fflush (stdout);
}
for (fd = 0; fd <= nfds; fd++)
{
if (fd != sd && FD_ISSET (fd, &readfds))
{
if (read_option(fd))
{
fflush (stdout);
close (fd);
FD_CLR (fd, &actfds);
}
}
}