@@ -29,46 +29,46 @@ let starttime = null;
2929let timeouttime = null;
3030const timeout = 1000;
3131
32- const echo_server = net.createServer(function (socket) {
32+ const echo_server = net.createServer((socket) => {
3333 socket.setTimeout(timeout);
3434
35- socket.on('timeout', function() {
35+ socket.on('timeout', () => {
3636 console.log('server timeout');
3737 timeouttime = new Date();
3838 console.dir(timeouttime);
3939 socket.destroy();
4040 });
4141
42- socket.on('error', function (e) {
42+ socket.on('error', (e) => {
4343 throw new Error(
4444 'Server side socket should not get error. We disconnect willingly.');
4545 });
4646
47- socket.on('data', function (d) {
47+ socket.on('data', (d) => {
4848 console.log(d);
4949 socket.write(d);
5050 });
5151
52- socket.on('end', function() {
52+ socket.on('end', () => {
5353 socket.end();
5454 });
5555});
5656
57- echo_server.listen(common.PORT, function() {
57+ echo_server.listen(common.PORT, () => {
5858 console.log(`server listening at ${common.PORT}`);
5959
6060 const client = net.createConnection(common.PORT);
6161 client.setEncoding('UTF8');
6262 client.setTimeout(0); // disable the timeout for client
63- client.on('connect', function() {
63+ client.on('connect', () => {
6464 console.log('client connected.');
6565 client.write('hello\r\n');
6666 });
6767
68- client.on('data', function (chunk) {
68+ client.on('data', (chunk) => {
6969 assert.strictEqual(chunk, 'hello\r\n');
7070 if (exchanges++ < 5) {
71- setTimeout(function() {
71+ setTimeout(() => {
7272 console.log('client write "hello"');
7373 client.write('hello\r\n');
7474 }, 500);
@@ -81,22 +81,22 @@ echo_server.listen(common.PORT, function() {
8181 }
8282 });
8383
84- client.on('timeout', function() {
84+ client.on('timeout', () => {
8585 throw new Error("client timeout - this shouldn't happen");
8686 });
8787
88- client.on('end', function() {
88+ client.on('end', () => {
8989 console.log('client end');
9090 client.end();
9191 });
9292
93- client.on('close', function() {
93+ client.on('close', () => {
9494 console.log('client disconnect');
9595 echo_server.close();
9696 });
9797});
9898
99- process.on('exit', function() {
99+ process.on('exit', () => {
100100 assert.ok(starttime != null);
101101 assert.ok(timeouttime != null);
102102
0 commit comments