相关疑难解决方法(0)

服务器套接字从chrome发送时收到2个http请求,当我从firefox发送时收到一个http请求

我在Linux下使用C语言编写了一个简单的服务器,它在localhost上侦听端口80.现在,当我从浏览器google chrome向程序发送请求时,它收到2个请求,而当我从firefox发送时只收到一个请求.

我在浏览器中输入的URL是:http://localhost/xyz.html

当我在CHROME中输入URL时输出

root@anirudh-Aspire-5920:/home/anirudh/workspace/DCMTOL# ./DCMTOL_RUN 

Inside HTTP server Handler

Inside HTTP request Handler 

**Detected request: clientsocket_fd = 6 clientportnumber = 38027**

GET /xyz.html HTTP/1.1

Host: localhost

Connection: keep-alive

Cache-Control: max-age=0

Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10

Accept-Encoding: gzip,deflate,sdch

Accept-Language: en-US,en;q=0.8

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


Inside HTTP request Handler

**Detected request: clientsocket_fd = 7 clientportnumber = 38029**

^C

root@anirudh-Aspire-5920:/home/anirudh/workspace/DCMTOL# 
Run Code Online (Sandbox Code Playgroud)

第二个请求不发送任何数据,所以我的代码在读取调用时等待,所以我必须终止它'^ C'.

我在FIREFOX中输入URL时的输出

root@anirudh-Aspire-5920:/home/anirudh/workspace/DCMTOL# ./DCMTOL_RUN 
Inside HTTP server Handler
Inside HTTP request Handler

**Detected …
Run Code Online (Sandbox Code Playgroud)

sockets http

28
推荐指数
2
解决办法
2万
查看次数

NodeJS服务器为每个请求将变量递增2

运行此代码时,i每次都会增加2,我无法在文档中查明,或者为什么会出现这种情况.我希望每个请求的增量都是1,但事实并非如此.为什么它的行为方式如此?

var http = require('http');
var i = 0;
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Number: ' + i + '\n');
  i++;
}).listen(8000, '127.0.0.1');
Run Code Online (Sandbox Code Playgroud)

javascript node.js

12
推荐指数
1
解决办法
3873
查看次数

标签 统计

http ×1

javascript ×1

node.js ×1

sockets ×1