共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 跳转至页
回复
打赏帖 | |
---|---|
C语言函数宏的三种封装方式被打赏50分 | |
嵌入式LinuxC语言程序调试和宏使用技巧被打赏50分 | |
让代码中包含最新的编译时间信息被打赏50分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769LVGL优化显示被打赏26分 | |
rtthread硬件加密--2crc加密分析被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769驱动ST7789以及显示优化被打赏36分 | |
【分享开发笔记,赚取电动螺丝刀】S32K146 PAL模拟I2C驱动适配被打赏23分 | |
我想要一部加热台+电源硬件设计规范被打赏16分 | |
我想要一部加热台+LED背光驱动芯片RT9293知识被打赏18分 | |
【分享开发笔记,赚取电动螺丝刀】S32K146 ADC 模块配置使用被打赏24分 |