1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 var net = require('net');
17 var assert = require('assert');
18 var timers = require('timers');
21 var server = net.createServer();
24 server.listen(port, 5);
26 server.on('connection', function(socket) {
27 socket.on('data', function(data) {
31 socket.on('close', function() {
35 // as soon as connection established, pause the socket
38 // resume after 2 secs
39 timers.setTimeout(function() {
45 var socket = new net.Socket();
48 socket.connect(port, "127.0.0.1");
49 socket.on('connect', function() {
50 // client writes "1" first, but server is paused for 2 secs
51 // server gets "1" after 2 secs
54 // "2" is appended to msg before "1"
55 timers.setTimeout(function() {
60 socket.on('end', function() {
64 process.on('exit', function(code) {
65 assert.equal(code, 0);
66 assert.equal(msg, "21");