网络图片传输

[code=C/C++][/code]
/*.c,运行在arm9 Linux开发板中*/
#
#
#
#
#
#
#
#
# PORT 4321
#8*1024
int main(int argc, char *argv[])
{
int ,;
FILE *;
int buf[]; // It is the
*host;
;
long int num;
(buf,0,(buf));
= fopen("test-mmap.jpg","rb");
/* if(-1 == (num = fread(buf,1,(buf),)))
{
("fopen");
exit(1);
}
("file words num is : %d\n\n",num);
*/
if(argc < 2) //It was 3 first time.
{
(,"USAGE:./ (or ip )Text\n");
exit(1);
}
if(NULL == (host = (argv[1])))
{
("");
exit(1);
}
//(buf,0,(buf));
//scanf("%s",buf);
//(buf,"%s",argv[2]);
if(-1 == ( = (,,0)))
{
("");
exit(1);
}
. = ;
. = htons(PORT);
. = *(( *)host->);
bzero(&(.),8);
if(-1 == (,(*)&,( )))

网络图片传输

文章插图
{
("");
exit(1);
}
if(-1 == (num = fread(buf,1,(buf),)))
{
("fopen");
exit(1);
}
if(-1 == ( = send(,buf,num,0))) //send()
{
("send");
exit(1);
}
if(num != )
{
("num != \n");
//break;
}
("file words num is :%d\n",num);
("----- is :%d\n\n",);
close();
close();
exit(0);
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
[code=C/C++][/code]
/*.c,运行在虚拟机Linux中*/
#
#
#
#
#
#
#
#
# PORT 4321 //PORTmust be the same with
#8*1024 // 1024 * 1024 =
#10
int main()
{
,;
int ,;
int ,;
FILE *;
char buf[];
long int num;
int ii;
【网络图片传输】if(-1 == ( = (,,0))) //
{
("");
网络图片传输

文章插图
exit(1);
}
(" id = %d()\n",);
. = ;
. = htons(PORT);
.. = ;
bzero(&(.),8);
int i = 1;
(,,,&i,(i));
if(-1 == bind(,(*)&,( )))
{
("bind");
exit(1);
}
("Bind !\n");
if(-1 == (,))
{
("");
exit(1);
}
("....\n");
if(-1 == ( = (,(*)&,&)))
{
("");
exit(1);
}
(buf,0,(buf));
if(-1 == ( = recv(,buf,(buf),0)))
{
("recv");
exit(1);
}
("(buf)= %d\n",(buf));
(" bytes num is :%d\n\n",);
//FILE * ;
= fopen("./test-mmap.jpg","wb");
if(-1 == (num = (buf,(buf),1,)))
{
(" date ");
exit(1);
}
// (" a : %s\n",buf);
close();
();
exit(0);
}
知道看别人的代码是件挺痛苦的事情,尤其是我这样的没有注释的代码(因为是在Linux下编程,没有安装中文输入法,英文太麻烦,反正是改的例子,所以就没写了)还好代码不是很长,还是很希望能有高人帮我看看,传输到虚拟机中图片总是显示不全,不知道问题出在哪里,在这里先谢谢了 。
自学嵌入式真不是一件容易的事情 。。。
这里是完整图片的样子
这是传输不完整的图片
总是丢失数据,小弟刚学编程,不知道哪里有什么问题需要注意,还请大虾们指点一下,感激不尽 。。。