I am trying to code a multi threaded echo server for a exercise, but its is causing me some problems. I am having trouble trying to figure out how to code it in a way it could accept unlimited number of clients. From what ive seen, I will need to set some max number of threads.
Can anyone offer me any suggestions?
Code:
main(int argc, char *argv[])
{
connection *conn;
pthread_t t[THREADS];
int i;
if (argc != 2) {
(void) fprintf(stderr, "usage: %s <appnum>\n", argv[0]);
exit(1);
}
/* wait for a connection from an echo client */
*conn = await_contact((appnum) atoi(argv[1]));
if (*conn < 0)
exit(1);
while(1){
pthread_create(&t[i], NULL, make_server, (void*) conn);
pthread_join(t[i], NULL);
}
return 0;
}
Can anyone offer me any suggestions?