A
A
alkhankhel2012-02-28 09:55:49
Node.js
alkhankhel, 2012-02-28 09:55:49

Problem with sending binary data by native http module

For example, I give a minimum of code that shows an error:

require('http').createServer(function (req, res) {
  var test = new Buffer(4);
  test.writeUInt32BE(2886731494, 0);

  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end(test);
}).listen(81, myServerIp);


The code should return a response with binary data, while the Content-Length will be set to exactly 4 bytes. This is the goal.
Problem:
The server is running on linux(gentoo);
the client (browser) is launched under linux (ubunta, suse), the response is given in 1-3 ms,
the client on windows 7, the response is in 220-240 ms.

The results are similar on different machines. Fast on Linux, slow on Windows.

When the floor task will work equally fast, regardless of the client's OS:
- If the same server is running on windows.
- If the task is to implement, for example, apache / php - echo pack ('N', 2886731494);
- If res.end(test.toString()), but the length of the header will not be 4 bytes, but 8. Which is not allowed.
- If the client contacts via the http 1.0 protocol (unfortunately there is no way to force it in the response)

Who will advise what? ;)

Ps different browsers were tried, the speed measurement was taken from the firebug and analogues.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alkhankhel, 2012-02-28
@alkhankhel

While I put nginx in front of the server, it helps. But I would still like to hear smart people.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question