3
3
Stability: 2 - Stable
4
4
5
5
The ` net ` module provides you with an asynchronous network wrapper. It contains
6
- methods for creating both servers and clients (called streams). You can include
7
- this module with ` require('net'); `
6
+ functions for creating both servers and clients (called streams). You can include
7
+ this module with ` require('net'); ` .
8
8
9
9
## net.createServer([ options] [ , connectionListener ] )
10
10
@@ -60,40 +60,17 @@ Use `nc` to connect to a UNIX domain socket server:
60
60
## net.connect(options[ , connectionListener] )
61
61
## net.createConnection(options[ , connectionListener] )
62
62
63
- A factory method , which returns a new [ 'net.Socket'] ( #net_class_net_socket )
64
- and connects to the supplied address and port .
63
+ A factory function , which returns a new [ 'net.Socket'] ( #net_class_net_socket )
64
+ and automatically connects with the supplied ` options ` .
65
65
66
- When the socket is established, the [ 'connect'] [ ] event will be emitted.
67
-
68
- Has the same events as [ 'net.Socket'] ( #net_class_net_socket ) .
69
-
70
- For TCP sockets, ` options ` argument should be an object which specifies:
71
-
72
- - ` port ` : Port the client should connect to (Required).
73
-
74
- - ` host ` : Host the client should connect to. Defaults to ` 'localhost' ` .
75
-
76
- - ` localAddress ` : Local interface to bind to for network connections.
77
-
78
- - ` localPort ` : Local port to bind to for network connections.
79
-
80
- - ` family ` : Version of IP stack. Defaults to ` 4 ` .
81
-
82
- For local domain sockets, ` options ` argument should be an object which
83
- specifies:
84
-
85
- - ` path ` : Path the client should connect to (Required).
86
-
87
- Common options are:
88
-
89
- - ` allowHalfOpen ` : if ` true ` , the socket won't automatically send
90
- a FIN packet when the other end of the socket sends a FIN packet.
91
- Defaults to ` false ` . See [ 'end'] [ ] event for more information.
66
+ The options are passed to both the [ 'net.Socket'] ( #net_class_net_socket )
67
+ constructor and the [ 'socket.connect'] ( #net_socket_connect_options_connectlistener )
68
+ method.
92
69
93
70
The ` connectListener ` parameter will be added as an listener for the
94
71
[ 'connect'] [ ] event.
95
72
96
- Here is an example of a client of echo server as described previously :
73
+ Here is an example of a client of the previously described echo server :
97
74
98
75
var net = require('net');
99
76
var client = net.connect({port: 8124},
@@ -117,22 +94,25 @@ changed to
117
94
## net.connect(port[ , host] [ , connectListener ] )
118
95
## net.createConnection(port[ , host] [ , connectListener ] )
119
96
120
- Creates a TCP connection to ` port ` on ` host ` . If ` host ` is omitted,
121
- ` 'localhost' ` will be assumed.
97
+ A factory function, which returns a new
98
+ [ 'net.Socket'] ( #net_class_net_socket ) and automatically connects to the
99
+ supplied ` port ` and ` host ` .
100
+
101
+ If ` host ` is omitted, ` 'localhost' ` will be assumed.
102
+
122
103
The ` connectListener ` parameter will be added as an listener for the
123
104
[ 'connect'] [ ] event.
124
105
125
- Is a factory method which returns a new [ 'net.Socket'] ( #net_class_net_socket ) .
126
-
127
106
## net.connect(path[ , connectListener] )
128
107
## net.createConnection(path[ , connectListener] )
129
108
130
- Creates unix socket connection to ` path ` .
109
+ A factory function, which returns a new unix
110
+ [ 'net.Socket'] ( #net_class_net_socket ) and automatically connects to the
111
+ supplied ` path ` .
112
+
131
113
The ` connectListener ` parameter will be added as an listener for the
132
114
[ 'connect'] [ ] event.
133
115
134
- A factory method which returns a new [ 'net.Socket'] ( #net_class_net_socket ) .
135
-
136
116
## Class: net.Server
137
117
138
118
This class is used to create a TCP or local server.
@@ -360,13 +340,26 @@ Set `readable` and/or `writable` to `true` to allow reads and/or writes on this
360
340
socket (NOTE: Works only when ` fd ` is passed).
361
341
About ` allowHalfOpen ` , refer to ` createServer() ` and ` 'end' ` event.
362
342
363
- ### socket.connect(port[ , host] [ , connectListener ] )
364
- ### socket.connect(path[ , connectListener] )
343
+ ### socket.connect(options[ , connectListener] )
344
+
345
+ Opens the connection for a given socket.
346
+
347
+ For TCP sockets, ` options ` argument should be an object which specifies:
365
348
366
- Opens the connection for a given socket. If ` port ` and ` host ` are given,
367
- then the socket will be opened as a TCP socket, if ` host ` is omitted,
368
- ` localhost ` will be assumed. If a ` path ` is given, the socket will be
369
- opened as a unix socket to that path.
349
+ - ` port ` : Port the client should connect to (Required).
350
+
351
+ - ` host ` : Host the client should connect to. Defaults to ` 'localhost' ` .
352
+
353
+ - ` localAddress ` : Local interface to bind to for network connections.
354
+
355
+ - ` localPort ` : Local port to bind to for network connections.
356
+
357
+ - ` family ` : Version of IP stack. Defaults to ` 4 ` .
358
+
359
+ For local domain sockets, ` options ` argument should be an object which
360
+ specifies:
361
+
362
+ - ` path ` : Path the client should connect to (Required).
370
363
371
364
Normally this method is not needed, as ` net.createConnection ` opens the
372
365
socket. Use this only if you are implementing a custom Socket.
@@ -378,6 +371,11 @@ will not be emitted, the `'error'` event will be emitted with the exception.
378
371
The ` connectListener ` parameter will be added as an listener for the
379
372
[ 'connect'] [ ] event.
380
373
374
+ ### socket.connect(port[ , host] [ , connectListener ] )
375
+ ### socket.connect(path[ , connectListener] )
376
+
377
+ As [ socket.connect(options[ , connectListener] )] ( #net_socket_connect_options_connectlistener ) ,
378
+ with options either as either ` {port: port, host: host} ` or ` {path: path} ` .
381
379
382
380
### socket.bufferSize
383
381
0 commit comments