File tree Expand file tree Collapse file tree 1 file changed +24
-13
lines changed Expand file tree Collapse file tree 1 file changed +24
-13
lines changed Original file line number Diff line number Diff line change 16
16
var net = require ( 'net' ) ;
17
17
var assert = require ( 'assert' ) ;
18
18
19
+ var server = net . createServer ( ) ;
20
+ var port = 22709 ;
21
+
19
22
var timedout = false ;
20
23
var connected = false ;
21
24
22
- // Try connect to host that is not exist (Reserved address of TEST-NET-1)
23
- var socket1 = net . createConnection ( 11111 , '192.0.2.1' ) ;
25
+ server . listen ( port , 1 ) ;
24
26
25
- socket1 . setTimeout ( 1000 ) ;
27
+ server . on ( 'connection' , function ( newSocket ) {
28
+ connected = true ;
29
+ console . log ( "Connected!" ) ;
26
30
27
- socket1 . on ( 'timeout' , function ( ) {
28
- timedout = true ;
29
- socket1 . destroy ( ) ;
30
- } ) ;
31
+ newSocket . on ( 'error' , function ( ) {
32
+ assert . fail ( ) ;
33
+ } ) ;
31
34
32
- socket1 . on ( 'error' , function ( ) {
33
- assert . fail ( ) ;
35
+ newSocket . setTimeout ( 500 ) ;
36
+
37
+ newSocket . on ( 'timeout' , function ( ) {
38
+ console . log ( "Timeout" ) ;
39
+ timedout = true ;
40
+ newSocket . destroy ( ) ;
41
+ socket . destroy ( ) ;
42
+ server . close ( ) ;
43
+ } ) ;
34
44
} ) ;
35
45
36
- socket1 . on ( 'connect' , function ( ) {
37
- connected = true ;
38
- socket1 . destroy ( ) ;
46
+ var socket = net . createConnection ( port ) ;
47
+
48
+ socket . on ( 'error' , function ( ) {
49
+ assert . fail ( ) ;
39
50
} ) ;
40
51
41
52
process . on ( 'exit' , function ( ) {
42
53
assert ( timedout ) ;
43
- assert ( ! connected ) ;
54
+ assert ( connected ) ;
44
55
} ) ;
You can’t perform that action at this time.
0 commit comments