共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 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| PCF8574功能模块及其使用被打赏¥20元 | |
| 传感器LSM6DSO及LIS3MDL的功能检测被打赏¥18元 | |
| LPS25HB气压传感器及其检测被打赏¥18元 | |
| HTS221温湿度传感器及其检测被打赏¥18元 | |
| 【S32K3XX】HSE FW 版本更新被打赏¥21元 | |
| 基于ArduinoUNO开发板的AT24C02读写测试被打赏¥16元 | |
| TCS3472S传感器及其色彩检测被打赏¥19元 | |
| 【S32DS】S32K3 RTD7.0.1 HSE 组件配置报错问题解决被打赏¥27元 | |
| 【S32K3XX】MCME 启动 CORE1被打赏¥23元 | |
| AG32VH407下温度大气压传感器及其检测被打赏¥20元 | |
我要赚赏金
