使用TCP / IP协议将视频文件从Android发送到C. [英] Sending a video file from Android to C using TCP/IP protocol.

查看:257
本文介绍了使用TCP / IP协议将视频文件从Android发送到C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试使用tcp / ip协议将视频文件从Android发送到C.当android发送视频文件时,我能够接收文件,但是当我播放文件时文件没有被播放,而且如果实际文件在使用tcp / ip接收后播放视频2分钟,则视频大小是3小时5分钟等等......



Hi,

I am trying to send a video file from Android to C using tcp/ip protocol. When android sends a video file, i am able to receive the file, but when i play the file the file is not getting played and moreover if the actual file plays a video for 2 minutes after receiving using tcp/ip the video size is about 3 hours 5 minutes and so on...

long long int receive_text(long long int socket)

{

   long long int buffersize = 0, recv_size = 0, size = 0, read_size, write_size;

   char textarray[8196000],errno;

   char verify[15] = "text Received";

   FILE *text;

   //Find the size of the text

   read(socket, &size, sizeof(int ));

   //Send our verification signal

   write(socket, &verify,sizeof(char));

   //Make sure that the size is bigger than 0

   /*if(size <= 0 )

   {

           printf("Error has occurred. Size less than or equal to 0 \n");

           return -1;

   } */

       text = fopen("/home/sosdt009/Desktop/receivedandroid.mp4","w");

       if( text == NULL)

   {

           printf("Error has occurred. text file could not be opened \n");

           return -1;

       }

       //Loop we have not received the entire file yet

       while(recv_size < size)

       {

               ioctl(socket, FIONREAD, &buffersize);

           //We check to see if there is data to be read from the socket

           if(buffersize > 0 )

   {

            if(read_size = read(socket, textarray, buffersize) < 0){

        printf("%s", strerror(errno));

       }

            //Write the currently read data into our text file

           write_size = fwrite(textarray,1, buffersize, text);

      /* if(write_size != buffersize)

       {

         printf("write and buffer sizes are wrong \n");

       }

       if(read_size != write_size)

       {

           printf("error in read write \n");

       }  */

       //Increment the total number of bytes read

      recv_size += read_size;

       //Send our handshake verification info

   write(socket, &verify,sizeof(char));

   if (read_size == write_size)

               {

                   printf("%lld,%lld", read_size, write_size);
                   printf("text successfully Received! \n");

                   }

           else

               {

                   //sleep(1000);
                   printf("%lld,%lld", read_size, write_size);
                   printf(" Data Received successfully: \n");

               }


     }

     }

   fclose(text);

   return 0;

}

推荐答案

最明显的问题是你忽略了你读取的块的大小( read_size )并始终将 buffersize 字节写入文件
the most obvious problem is you ignore the size of the chunk your read (read_size) and always write buffersize bytes to the file


这篇关于使用TCP / IP协议将视频文件从Android发送到C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆