tcp-port-used 0.0.6 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.jshintrc CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "browser" : false,
3
- "curly" : false,
3
+ "curly" : true,
4
4
  "devel" : false,
5
5
  "eqeqeq" : true,
6
6
  "eqnull" : true,
@@ -14,7 +14,6 @@
14
14
  "laxcomma" : true,
15
15
  "maxcomplexity" : 39,
16
16
  "maxdepth" : 5,
17
- "maxlen" : 110,
18
17
  "maxparams" : 7,
19
18
  "maxstatements" : 100,
20
19
  "multistr" : true,
@@ -30,7 +29,7 @@
30
29
  "strict" : false,
31
30
  "swindent" : true,
32
31
  "sub" : true,
33
- "trailing" : true,
32
+ "trailing" : false,
34
33
  "undef" : true,
35
34
  "unused" : true,
36
35
 
package/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  tcp-port-used
2
2
  =============
3
3
 
4
- A simple Node.js module to check if a TCP localhost port is currently in use. It
5
- returns a promise from the q library.
6
-
7
- Note: You must have admin privs to successfully test system ports (0-1023).
4
+ A simple Node.js module to check if a TCP port is currently in use. It returns a
5
+ deferred promise from the q library.
8
6
 
9
7
  ## Installation
10
8
 
@@ -15,79 +13,167 @@ To check a port's state:
15
13
 
16
14
  var tcpPortUsed = require('tcp-port-used');
17
15
 
18
- tcpPortUsed.check(44201)
16
+ tcpPortUsed.check(44201, '127.0.0.1')
19
17
  .then(function(inUse) {
20
18
  console.log('Port 44201 usage: '+inUse);
21
19
  }, function(err) {
22
- console.error('Error on check: '+err.message);
20
+ console.error('Error on check:', err.message);
23
21
  });
24
22
 
25
- To wait until a port is available:
23
+ To wait until a port on localhost is available:
26
24
 
27
25
  tcpPortUsed.waitUntilFree(44203, 500, 4000)
28
26
  .then(function() {
29
27
  console.log('Port 44203 is now free.');
30
28
  }, function(err) {
31
- console.loh('Error: ', error.message);
29
+ console.log('Error:', err.message);
30
+ });
31
+
32
+ To wait until a port on a host is available:
33
+
34
+ tcpPortUsed.waitUntilFreeOnHost(44203, 'some.host.com', 500, 4000)
35
+ .then(function() {
36
+ console.log('Port 44203 on some.host.com is now free.');
37
+ }, function(err) {
38
+ console.log('Error:', err.message);
32
39
  });
33
40
 
34
- To wait until a port is accepting connections:
41
+ To wait until a port on localhost is accepting connections:
35
42
 
36
43
  tcpPortUsed.waitUntilUsed(44204, 500, 4000)
37
44
  .then(function() {
38
45
  console.log('Port 44204 is now in use.');
39
46
  }, function(err) {
40
- console.loh('Error: ', error.message);
47
+ console.log('Error:', err.message);
48
+ });
49
+
50
+ To wait until a port on a host is accepting connections:
51
+
52
+ tcpPortUsed.waitUntilUsedOnHost(44204, 'some.host.com', 500, 4000)
53
+ .then(function() {
54
+ console.log('Port 44204 on some.host.com is now in use.');
55
+ }, function(err) {
56
+ console.log('Error:', err.message);
41
57
  });
42
58
 
59
+ To wait until a port on a host is in specific state:
60
+
61
+ var inUse = true; // wait until the port is in use
62
+ tcpPortUsed.waitForStatus(44204, 'some.host.com', inUse, 500, 4000)
63
+ .then(function() {
64
+ console.log('Port 44204 on some.host.com is now in use.');
65
+ }, function(err) {
66
+ console.log('Error:', err.message);
67
+ });
68
+
69
+
43
70
  ## API
44
71
 
72
+ ### check(port [, host])
73
+ Checks if a TCP port is in use by attempting to connect to the port on host.
74
+ If no host is specified, the module uses '127.0.0.1' (localhost). When the
75
+ promise is resolved, there is a parameter `inUse`, when true means the port is
76
+ in use and false means the port is free.
77
+
78
+ **Parameters:**
79
+
80
+ * **Number|Object** *port* The port you are curious to see if available. If an
81
+ object, must contain all the parameters as properties.
82
+ * **String** *host* The host name or IP address of the host. Default, if not defined: '127.0.0.1'
83
+
84
+ **Returns:**
45
85
 
46
- ### check(port)
47
- Checks if a TCP port is in use by creating the socket and binding it to the
48
- target port. Once bound, successfully, it's assume the port is availble.
49
- After the socket is closed or in error, the promise is resolved.
50
- Note: you have to be super user to correctly test system ports (0-1023).
86
+ **Object** A deferred promise from the q module.
51
87
 
52
- **Param:**
88
+ ### waitUntilFree(port [, retryTimeMs] [, timeOutMs])
89
+ Returns a deferred promise and fulfills it only when the localhost socket is
90
+ free. Will retry on an interval specified in retryTimeMs until the timeout. If
91
+ not defined the retryTime is 200 ms and the timeout is 2000 ms.
53
92
 
54
- **Number** *port* The port you are curious to see if available.
93
+ **Parameters:**
94
+
95
+ * **Number|Object** *port* a valid TCP port number. If an object must contain
96
+ all the parameters as properties.
97
+ * **Number** *[retryTimeMs]* the retry interval in milliseconds - defaultis is 100ms.
98
+ * **Number** *[timeOutMs]* the amount of time to wait until port is free. Default 300ms.
55
99
 
56
100
  **Returns:**
57
101
 
58
- **Object** A deferred Q promise.
102
+ **Object** A deferred promise from the q module.
59
103
 
60
- ### waitUntilFree(port, [retryTimeMs], [timeOutMs])
61
- Creates a deferred promise and fulfills it only when the socket is free.
62
- Will retry on an interval specified in retryTimeMs.
63
- Note: you have to be super user to correctly test system ports (0-1023).
64
104
 
65
- **Params:**
105
+ ### waitUntilFreeOnHost(port [, host] [, retryTimeMs] [, timeOutMs])
106
+ Returns a deferred promise and fulfills it only when the localhost socket is
107
+ free. Will retry on an interval specified in retryTimeMs until the timeout. If
108
+ not defined the retryTime is 200 ms and the timeout is 2000 ms. If the host is
109
+ not defined, the modules uses the default '127.0.0.1'.
66
110
 
67
- * **Number** *port* a valid TCP port number
111
+ **Parameters:**
112
+
113
+ * **Number|Object** *port* a valid TCP port number. If an object, must contain
114
+ all the parameters as properties.
115
+ * **String** *host* The host name or IP address of the host. Default, if not defined: '127.0.0.1'
68
116
  * **Number** *[retryTimeMs]* the retry interval in milliseconds - defaultis is 100ms.
69
117
  * **Number** *[timeOutMs]* the amount of time to wait until port is free. Default 300ms.
70
118
 
71
119
  **Returns:**
72
120
 
73
- **Object** A deferred Q promise.
121
+ **Object** A deferred promise from the q module.
122
+
123
+ ### waitUntilUsed(port [, retryTimeMs] [, timeOutMs])
124
+ Returns a deferred promise and fulfills it only when the socket is accepting
125
+ connections. Will retry on an interval specified in retryTimeMs until the
126
+ timeout. If the host is not defined the retryTime is 200 ms and the timeout is
127
+ 2000 ms.
128
+
129
+ **Parameters:**
130
+
131
+ * **Number|Object** *port* a valid TCP port number. If an object, must contain
132
+ all the parameters as properties.
133
+ * **Number** *[retryTimeMs]* the retry interval in milliseconds - defaultis is 100ms.
134
+ * **Number** *[timeOutMs]* the amount of time to wait until port is free. Default 300ms.
135
+
136
+ **Returns:**
74
137
 
75
- ### waitUntilUsed(port, [retryTimeMs], [timeOutMs])
138
+ **Object** A deferred promise from the q module.
76
139
 
77
- Creates a deferred promise and fulfills it only when the socket is used.
78
- Will retry on an interval specified in retryTimeMs.
79
- Note: you have to be super user to correctly test system ports (0-1023).
140
+ ### waitUntilUsedOnHost(port [, host] [, retryTimeMs] [, timeOutMs])
141
+ Returns a deferred promise and fulfills it only when the socket is accepting
142
+ connections. Will retry on an interval specified in retryTimeMs until the
143
+ timeout. If not defined the retryTime is 200 ms and the timeout is 2000 ms.
144
+ If the host is not defined the module uses the default '127.0.0.1'.
80
145
 
81
- **Params:**
146
+ **Parameters:**
82
147
 
83
- * **Number** *port* a valid TCP port number
84
- * **Number** *[retryTimeMs]* the retry interval in milliseconds - defaultis is 500ms
85
- * **Number** *[timeOutMs]* the amount of time to wait until port is free
148
+ * **Number|Object** *port* a valid TCP port number. If an object, must contain
149
+ all the parameters as properties.
150
+ * **String** *host* The host name or IP address of the host. Default, if not defined: '127.0.0.1'
151
+ * **Number** *[retryTimeMs]* the retry interval in milliseconds - defaultis is 100ms.
152
+ * **Number** *[timeOutMs]* the amount of time to wait until port is free. Default 300ms.
86
153
 
87
154
  **Returns:**
88
155
 
89
- **Object** A deferred Q promise.
156
+ **Object** A deferred promise from the q module.
157
+
158
+ ### waitForStatus(port, host, status [, retryTimeMs] [, timeOutMs])
159
+ Waits until the port on host matches the boolean status in terms of use. If the
160
+ status is true, the promise defers until the port is in use. If the status is
161
+ false the promise defers until the port is free. If the host is undefined or
162
+ null, the module uses the default '127.0.0.1'. Also, if not defined the
163
+ retryTime is 200 ms and the timeout is 2000 ms.
164
+
165
+ **Parameters:**
166
+
167
+ * **Number** *port* a valid TCP port number. If an object, must contain all the
168
+ parameters as properties.
169
+ * **String** *host* The host name or IP address of the host. Default, if not defined: '127.0.0.1'
170
+ * **Boolean** *status* A boolean describing the condition to wait for in terms of "in use." True indicates wait until the port is in use. False indicates wait until the port is free.
171
+ * **Number** *[retryTimeMs]* the retry interval in milliseconds - defaultis is 100ms.
172
+ * **Number** *[timeOutMs]* the amount of time to wait until port is free. Default 300ms.
173
+
174
+ **Returns:**
90
175
 
176
+ **Object** A deferred promise from the q module.
91
177
 
92
178
  ## License
93
179