共2条
1/1 1 跳转至页
arm arm 嵌入式系统实验教程三中 附加实验 不明白的一段实验代码

问
while(1)
{
sin_size = sizeof(struct sockaddr_in);
/* Wait a connection, and obtain a new socket file despriptor for single connection */
if ((nsockfd = accept(sockfd, (struct sockaddr *)&addr_remote, &sin_size)) == -1)
{
printf ("ERROR: Obtain new Socket Despcritor error\n");
continue;
}
else
{
printf ("OK: Server has got connect from %s\n", inet_ntoa(addr_remote.sin_addr));
}
num = recv(nsockfd, revbuf, LENGTH, 0);
/* Child process */
if(!vfork())
{
printf("OK: Http web is servering.\n");
if(revbuf[5]==' ')
{
send(nsockfd, httpweb, 168, 0);
send(nsockfd, web, 500, 0);
}
else if(revbuf[5]=='1')
{
send(nsockfd, httpgif, 168, 0);
send(nsockfd, bmp, 442, 0);
}
}
close(nsockfd);
while(waitpid(-1, NULL, WNOHANG) > 0);
这是一个web 服务程序的部分代码,请问 revbuf[5]中是什么内容,为什么可以这样写
答 1: 你看看发端是什么呢?recv()中的buf就是socket中收到的数据,看看这个链接
http://msdn.microsoft.com/library/?url=/library/en-us/winsock/winsock/recv_2.asp
{
sin_size = sizeof(struct sockaddr_in);
/* Wait a connection, and obtain a new socket file despriptor for single connection */
if ((nsockfd = accept(sockfd, (struct sockaddr *)&addr_remote, &sin_size)) == -1)
{
printf ("ERROR: Obtain new Socket Despcritor error\n");
continue;
}
else
{
printf ("OK: Server has got connect from %s\n", inet_ntoa(addr_remote.sin_addr));
}
num = recv(nsockfd, revbuf, LENGTH, 0);
/* Child process */
if(!vfork())
{
printf("OK: Http web is servering.\n");
if(revbuf[5]==' ')
{
send(nsockfd, httpweb, 168, 0);
send(nsockfd, web, 500, 0);
}
else if(revbuf[5]=='1')
{
send(nsockfd, httpgif, 168, 0);
send(nsockfd, bmp, 442, 0);
}
}
close(nsockfd);
while(waitpid(-1, NULL, WNOHANG) > 0);
这是一个web 服务程序的部分代码,请问 revbuf[5]中是什么内容,为什么可以这样写
答 1: 你看看发端是什么呢?recv()中的buf就是socket中收到的数据,看看这个链接
http://msdn.microsoft.com/library/?url=/library/en-us/winsock/winsock/recv_2.asp
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
电流检测模块MAX4080S被打赏10分 | |
【我踩过的那些坑】calloc和malloc错误使用导致跑飞问题排查被打赏50分 | |
多组DCTODC电源方案被打赏50分 | |
【我踩过的那些坑】STM32cubeMX软件的使用过程中的“坑”被打赏50分 | |
新手必看!C语言精华知识:表驱动法被打赏50分 | |
【我踩过的那些坑】杜绑线问题被打赏50分 | |
【我踩过的那些坑】STM32的硬件通讯调试过程的“坑”被打赏50分 | |
【我踩过的那些坑】晶振使用的问题被打赏100分 | |
【我踩过的那些坑】电感选型错误导致的处理器连接不上被打赏50分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏10分 |