Dear all,
I have a simple multi-threaded TCP client/server application. In it, the
client can send virutally all text-based (ASCII) file correctly and easily.
However, when I try to send a binary file (e.g., a video file, a tar file or
even PDF), the client side almost always get "Broken Pipe" error. The
client is supposed to send blocks of data obtained from a global queue
structure. The queue is never empty.
Since FTP requires the user to specify whether a file is ASCII or binary, I
think suspecting that binary file transfers may need special treatment?
The codes I used at the client side is very simple and nothing special. I
just post it here in case it helps.
Thanks very much in advance.
Regards,
Patrick
while ((glob_qptr->front) != NULL)
{
//The client is supposed to send blocks of data_struct from a global
queue structure.
headofq = (struct data_struct *)malloc(sizeof(struct data_struct));
pthread_mutex_lock(&glob_mx);
headofq = glob_qptr->front;
headofq->thread_number = s_args->thread_number; //Assign the thread
number to each outgoing piece of data.
gettimeofday(&now, NULL); //Obtain the current time at the sender.
headofq->t_timestamp = now.tv_sec*1000 + now.tv_usec/1000;
if (headofq->next != NULL)
{
glob_qptr->front = headofq->next;
}
glob_qptr->queue_len--;
pthread_mutex_unlock(&glob_mx);
n = write(sockfd, headofq, sizeof(struct data_struct));
fprintf(debug_file, "Data sent from thread %ld \n", pthread_self());
if (headofq->next != NULL)
{
glob_qptr->front = headofq->next;
}
headofq = NULL;
free(headofq);
}
|