I use the send() function to send data over a TCP/IP connection. The send() function is used in a loop as follow:
[code] //----- connect to server -----
if ( connect( sid_local, (struct sockaddr*)&server_addr, sizeof(server_addr) ) == 0 )
{
printf(“TCP CLIENT: connected to %s\n”, Client_parameters->server_IP );
do {
//nb_sent = send( sid_local, tx_buffer , block_size, 0 ); // sending data to server
nb_sent = write( sid_local, tx_buffer , block_size ); // sending data to server
} while (nb_sent > 0);
}[/code]
Whenever the server stop the program exits and gives the following error:
TCP_test terminated with signal 13
I expected the loop to end and the program to continue not to exit.
Then, my question is how to properly exit the loop when the server close the connection?