共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 跳转至页
回复
有奖活动 | |
---|---|
“我踩过的那些坑”主题活动——第002期 | |
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |