Hi all,
I have designed a client that sends info to a server every half hour. The server is threaded and each connection is handled by a separate thread. 99% of the times it works just fine, but every now and then I get the following output at the server side:
--------------------------------------------------------------
Accepted a connection
Started thread 3205701312
Received 500 bytes in 1st iteration
Received 85 bytes in 2nd iteration
Server received 585 bytes from the client
ALL DONE OK
Accepted a connection
Started thread 3214089792
Received 500 bytes in 1st iteration
Received 139 bytes in 2nd iteration
Server received 639 bytes from the client
ALL DONE OK
Accepted a connection
Started thread 3214089792
Accepted a connection
Started thread 3214089792
Accepted a connection
Started thread 3214089792
Accepted a connection
Started thread 3214089792
.
.
.
----------------------------------------------------------------------------------
I have not been able to replicate this. Question: How come it gives the same thread id to a new incoming connection. That was my whole point in making it threaded that if one of the threads hang or something goes wrong, I should still be able to received data from the client.
Here is the code snippet:
----------------------------------------------------------------------------------
void *process_connection( void *arg) {}
for(;
{
// Accept a new connection
len = sizeof (server_ssin);
if ((client = accept(server_socket, (struct sockaddr *)&server_ssin, &len)) < 0) {
perror("Error accepting connection ");
fprintf(server_outputFile,"Error accepting connection ");
fflush(server_outputFile);
break;
//return -1;
}
printf ("Accepted a connection\n");
fprintf (server_outputFile,"Accepted a connection\n");
fflush(server_outputFile);
pthread_create(&pt,NULL,process_connection,(void *) client);
printf("Started thread %u\n",pt);
fprintf(server_outputFile, "Started thread %u\n",pt);
fflush(server_outputFile);
} // end of infinite for loop
----------------------------------------------------------------------------------
Any suggestions or help whatsoever is most welcome.
thank you very much
dravya