{"size": 644, "ext": "js", "max_stars_repo_path": "test/support/server_end.js", "max_stars_repo_name": "kookxiang/tcp-base", "max_stars_repo_stars_event_min_datetime": "2016-11-11T18:55:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-17T01:56:03.000Z", "max_issues_repo_path": "test/support/server_end.js", "max_issues_repo_name": "kookxiang/tcp-base", "max_issues_repo_issues_event_min_datetime": "2016-09-16T11:16:22.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-28T15:08:41.000Z", "max_forks_repo_path": "test/support/server_end.js", "max_forks_repo_name": "kookxiang/tcp-base", "max_forks_repo_forks_event_min_datetime": "2017-01-04T09:34:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-29T03:39:41.000Z"}
{"max_stars_count": 30, "max_issues_count": 12, "max_forks_count": 12, "avg_line_length": 22.2068965517, "max_line_length": 108, "alphanum_fraction": 0.6086956522}
'use strict';

const net = require('net');

let server;
exports.start = function(port, end, cb) {
  server = net.createServer({
    allowHalfOpen: true,
  }, socket => {
    socket.write(new Buffer('0000001a000000007b226964223a302c226d657373616765223a2268656c6c6f227d', 'hex'));
    console.log('socket connect', socket.remoteAddress);
    socket.on('data', data => {
      console.log('receive', data.toString());
    });

    if (end) {
      setTimeout(() => {
        console.log('end the socket');
        socket.end();
      }, 3000);
    }
  });
  server.listen(port, cb);
};

exports.close = function() {
  server && server.close();
};
