J
J
JackShcherbakov2018-02-14 21:50:40
PHP
JackShcherbakov, 2018-02-14 21:50:40

How to set network packet breakpoint?

Hello! I am reading this article about XMLHttpRequest. There is nodeJs code, which is not entirely clear to me, since I am not familiar with NodeJs, and I write server scripts in PHP.
The code itself:

var http = require('http');
var url = require('url');
var querystring = require('querystring');
var static = require('node-static');
var file = new static.Server('.');

function accept(req, res) {

  if (req.url == '/digits') {

    res.writeHead(200, {
      'Content-Type': 'text/plain',
      'Cache-Control': 'no-cache'
    });

    var i = 0;

    var timer = setInterval(write, 1000);
    write();

    function write() {
      res.write(new Array(1000).join(++i + '') + ' ');
      if (i == 9) {
        clearInterval(timer);
        res.end();
      }

    }
  } else {
    file.serve(req, res);
  }
}



// ----- запуск accept как сервера из консоли или как модуля ------

if (!module.parent) {
  http.createServer(accept).listen(8080);
} else {
  exports.accept = accept;
}


Here is the code that does it all - https://learn.javascript.ru/article/ajax-xmlhttpre...

This code sends packets with a gap of every 1000 characters. So. Will this gap always and everywhere be the same, or can this gap be established by yourself? If possible, how to do it in PHP?

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2018-02-14
@JackShcherbakov

var timer = setInterval(write, 1000); // <---
 write();

 res.write(new Array(1000).join(++i + '') + ' ');  // <---

not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question