@@ -130,7 +130,7 @@ as a string.
130
130
const server = net .createServer ((socket ) => {
131
131
socket .end (' goodbye\n ' );
132
132
}).on (' error' , (err ) => {
133
- // handle errors here
133
+ // Handle errors here.
134
134
throw err;
135
135
});
136
136
@@ -147,7 +147,7 @@ Don't call `server.address()` until the `'listening'` event has been emitted.
147
147
added: v0.1.90
148
148
-->
149
149
150
- * ` callback ` {Function} Called when the server is closed
150
+ * ` callback ` {Function} Called when the server is closed.
151
151
* Returns: {net.Server}
152
152
153
153
Stops the server from accepting new connections and keeps existing
@@ -165,6 +165,8 @@ deprecated: v0.9.7
165
165
166
166
> Stability: 0 - Deprecated: Use [ ` server.getConnections() ` ] [ ] instead.
167
167
168
+ * {integer|null}
169
+
168
170
The number of concurrent connections on the server.
169
171
170
172
This becomes ` null ` when sending a socket to a child with
@@ -269,9 +271,9 @@ changes:
269
271
functions.
270
272
* ` exclusive ` {boolean} ** Default:** ` false `
271
273
* ` readableAll ` {boolean} For IPC servers makes the pipe readable
272
- for all users. ** Default:** ` false `
274
+ for all users. ** Default:** ` false ` .
273
275
* ` writableAll ` {boolean} For IPC servers makes the pipe writable
274
- for all users. ** Default:** ` false `
276
+ for all users. ** Default:** ` false ` .
275
277
* ` ipv6Only ` {boolean} For TCP servers, setting ` ipv6Only ` to ` true ` will
276
278
disable dual-stack support, i.e., binding to host ` :: ` won't make
277
279
` 0.0.0.0 ` be bound. ** Default:** ` false ` .
@@ -354,6 +356,8 @@ added: v5.7.0
354
356
added: v0.2.0
355
357
-->
356
358
359
+ * {integer}
360
+
357
361
Set this property to reject connections when the server's connection count gets
358
362
high.
359
363
@@ -542,6 +546,8 @@ socket as reported by the operating system:
542
546
added: v0.3.8
543
547
-->
544
548
549
+ * {integer}
550
+
545
551
` net.Socket ` has the property that ` socket.write() ` always works. This is to
546
552
help users get up and running quickly. The computer cannot always keep up
547
553
with the amount of data that is written to a socket - the network connection
@@ -564,13 +570,17 @@ Users who experience large or growing `bufferSize` should attempt to
564
570
added: v0.5.3
565
571
-->
566
572
573
+ * {integer}
574
+
567
575
The amount of received bytes.
568
576
569
577
### socket.bytesWritten
570
578
<!-- YAML
571
579
added: v0.5.3
572
580
-->
573
581
582
+ * {integer}
583
+
574
584
The amount of bytes sent.
575
585
576
586
### socket.connect()
@@ -659,10 +669,10 @@ const net = require('net');
659
669
net .connect ({
660
670
port: 80 ,
661
671
onread: {
662
- // Reuses a 4KiB Buffer for every read from the socket
672
+ // Reuses a 4KiB Buffer for every read from the socket.
663
673
buffer: Buffer .alloc (4 * 1024 ),
664
674
callback : function (nread , buf ) {
665
- // Received data is available in `buf` from 0 to `nread`
675
+ // Received data is available in `buf` from 0 to `nread`.
666
676
console .log (buf .toString (' utf8' , 0 , nread));
667
677
}
668
678
}
@@ -705,6 +715,8 @@ called with `{port: port, host: host}` as `options`.
705
715
added: v6.1.0
706
716
-->
707
717
718
+ * {boolean}
719
+
708
720
If ` true ` ,
709
721
[ ` socket.connect(options[, connectListener]) ` ] [ `socket.connect(options)` ] was
710
722
called and has not yet finished. It will stay ` true ` until the socket becomes
@@ -732,7 +744,7 @@ listeners for that event will receive `exception` as an argument.
732
744
* {boolean} Indicates if the connection is destroyed or not. Once a
733
745
connection is destroyed no further data can be transferred using it.
734
746
735
- ### socket.end([ data] [ , encoding ] [ , callback] )
747
+ ### socket.end([ data[ , encoding] ][ , callback ] )
736
748
<!-- YAML
737
749
added: v0.1.90
738
750
-->
@@ -753,6 +765,8 @@ If `data` is specified, it is equivalent to calling
753
765
added: v0.9.6
754
766
-->
755
767
768
+ * {string}
769
+
756
770
The string representation of the local IP address the remote client is
757
771
connecting on. For example, in a server listening on ` '0.0.0.0' ` , if a client
758
772
connects on ` '192.168.1.1' ` , the value of ` socket.localAddress ` would be
@@ -763,6 +777,8 @@ connects on `'192.168.1.1'`, the value of `socket.localAddress` would be
763
777
added: v0.9.6
764
778
-->
765
779
780
+ * {integer}
781
+
766
782
The numeric representation of the local port. For example, ` 80 ` or ` 21 ` .
767
783
768
784
### socket.pause()
@@ -799,6 +815,8 @@ If the socket is `ref`ed calling `ref` again will have no effect.
799
815
added: v0.5.10
800
816
-->
801
817
818
+ * {string}
819
+
802
820
The string representation of the remote IP address. For example,
803
821
` '74.125.127.100' ` or ` '2001:4860:a005::68' ` . Value may be ` undefined ` if
804
822
the socket is destroyed (for example, if the client disconnected).
@@ -808,13 +826,17 @@ the socket is destroyed (for example, if the client disconnected).
808
826
added: v0.11.14
809
827
-->
810
828
829
+ * {string}
830
+
811
831
The string representation of the remote IP family. ` 'IPv4' ` or ` 'IPv6' ` .
812
832
813
833
### socket.remotePort
814
834
<!-- YAML
815
835
added: v0.5.10
816
836
-->
817
837
838
+ * {integer}
839
+
818
840
The numeric representation of the remote port. For example, ` 80 ` or ` 21 ` .
819
841
820
842
### socket.resume()
@@ -946,6 +968,7 @@ added: v0.7.0
946
968
947
969
* ` options ` {Object}
948
970
* ` connectListener ` {Function}
971
+ * Returns: {net.Socket}
949
972
950
973
Alias to
951
974
[ ` net.createConnection(options[, connectListener]) ` ] [ `net.createConnection(options)` ] .
@@ -957,6 +980,7 @@ added: v0.1.90
957
980
958
981
* ` path ` {string}
959
982
* ` connectListener ` {Function}
983
+ * Returns: {net.Socket}
960
984
961
985
Alias to
962
986
[ ` net.createConnection(path[, connectListener]) ` ] [ `net.createConnection(path)` ] .
@@ -969,6 +993,7 @@ added: v0.1.90
969
993
* ` port ` {number}
970
994
* ` host ` {string}
971
995
* ` connectListener ` {Function}
996
+ * Returns: {net.Socket}
972
997
973
998
Alias to
974
999
[ ` net.createConnection(port[, host][, connectListener]) ` ] [ `net.createConnection(port, host)` ] .
@@ -1023,7 +1048,7 @@ in the [`net.createServer()`][] section:
1023
1048
``` js
1024
1049
const net = require (' net' );
1025
1050
const client = net .createConnection ({ port: 8124 }, () => {
1026
- // 'connect' listener
1051
+ // 'connect' listener.
1027
1052
console .log (' connected to server!' );
1028
1053
client .write (' world!\r\n ' );
1029
1054
});
@@ -1077,7 +1102,7 @@ added: v0.1.90
1077
1102
* ` connectListener ` {Function} Common parameter of the
1078
1103
[ ` net.createConnection() ` ] [ ] functions, an "once" listener for the
1079
1104
` 'connect' ` event on the initiating socket. Will be passed to
1080
- [ ` socket.connect(path [, connectListener]) ` ] [ `socket.connect(port, host)` ] .
1105
+ [ ` socket.connect(port[, host] [, connectListener]) ` ] [ `socket.connect(port, host)` ] .
1081
1106
* Returns: {net.Socket} The newly created socket used to start the connection.
1082
1107
1083
1108
Initiates a TCP connection.
@@ -1124,7 +1149,7 @@ on port 8124:
1124
1149
``` js
1125
1150
const net = require (' net' );
1126
1151
const server = net .createServer ((c ) => {
1127
- // 'connection' listener
1152
+ // 'connection' listener.
1128
1153
console .log (' client connected' );
1129
1154
c .on (' end' , () => {
1130
1155
console .log (' client disconnected' );
@@ -1193,6 +1218,9 @@ added: v0.3.0
1193
1218
1194
1219
Returns ` true ` if input is a version 6 IP address, otherwise returns ` false ` .
1195
1220
1221
+ [ IPC ] : #net_ipc_support
1222
+ [ Identifying paths for IPC connections ] : #net_identifying_paths_for_ipc_connections
1223
+ [ Readable Stream ] : stream.html#stream_class_stream_readable
1196
1224
[ `'close'` ] : #net_event_close
1197
1225
[ `'connect'` ] : #net_event_connect
1198
1226
[ `'connection'` ] : #net_event_connection
@@ -1238,9 +1266,6 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
1238
1266
[ `socket.setEncoding()` ] : #net_socket_setencoding_encoding
1239
1267
[ `socket.setTimeout()` ] : #net_socket_settimeout_timeout_callback
1240
1268
[ `socket.setTimeout(timeout)` ] : #net_socket_settimeout_timeout_callback
1241
- [ IPC ] : #net_ipc_support
1242
- [ Identifying paths for IPC connections ] : #net_identifying_paths_for_ipc_connections
1243
- [ Readable Stream ] : stream.html#stream_class_stream_readable
1244
1269
[ half-closed ] : https://tools.ietf.org/html/rfc1122
1245
1270
[ stream_writable_write ] : stream.html#stream_writable_write_chunk_encoding_callback
1246
1271
[ unspecified IPv4 address ] : https://en.wikipedia.org/wiki/0.0.0.0
0 commit comments