@@ -35,13 +35,14 @@ The arguments for this method change the type of connection:
3535
3636 Creates unix socket connection to ` path `
3737
38- The ` callback ` parameter will be added as an listener for the 'connect` event.
38+ The ` callback ` parameter will be added as an listener for the ` 'connect' ` event.
3939
4040---
4141
4242### net.Server
4343
4444This class is used to create a TCP or UNIX server.
45+ A server is a ` net.Socket ` that can listen for new incoming connections.
4546
4647Here is an example of a echo server which listens for connections
4748on port 8124:
@@ -66,20 +67,18 @@ Use `nc` to connect to a UNIX domain socket server:
6667
6768 nc -U /tmp/echo.sock
6869
69- ` net.Server ` is an ` EventEmitter ` with the following events:
70-
7170#### server.listen(port, [ host] , [ callback] )
7271
7372Begin accepting connections on the specified ` port ` and ` host ` . If the
7473` host ` is omitted, the server will accept connections directed to any
75- IPv4 address (` INADDR_ANY ` ).
74+ IPv4 address (` INADDR_ANY ` ). A port value of zero will assign a random port.
7675
7776This function is asynchronous. The last parameter ` callback ` will be called
7877when the server has been bound.
7978
80- One issue some users run into is getting ` EADDRINUSE ` errors. Meaning
79+ One issue some users run into is getting ` EADDRINUSE ` errors. This means that
8180another server is already running on the requested port. One way of handling this
82- would be to wait a second and the try again. This can be done with
81+ would be to wait a second and then try again. This can be done with
8382
8483 server.on('error', function (e) {
8584 if (e.code == 'EADDRINUSE') {
@@ -149,6 +148,15 @@ Set this property to reject connections when the server's connection count gets
149148
150149The number of concurrent connections on the server.
151150
151+
152+ ` net.Server ` is an ` EventEmitter ` with the following events:
153+
154+ #### Event: 'listening'
155+
156+ ` function () {} `
157+
158+ Emitted when the server has been bound after calling ` server.listen ` .
159+
152160#### Event: 'connection'
153161
154162` function (socket) {} `
@@ -162,17 +170,22 @@ Emitted when a new connection is made. `socket` is an instance of
162170
163171Emitted when the server closes.
164172
173+ #### Event: 'error'
174+
175+ ` function (exception) {} `
176+
177+ Emitted when an error occurs. The ` 'close' ` event will be called directly
178+ following this event. See example in discussion of ` server.listen ` .
179+
165180---
166181
167182### net.Socket
168183
169- This object is an abstraction of of a TCP or UNIX socket. ` net.Socket `
184+ This object is an abstraction of a TCP or UNIX socket. ` net.Socket `
170185instances implement a duplex Stream interface. They can be created by the
171186user and used as a client (with ` connect() ` ) or they can be created by Node
172187and passed to the user through the ` 'connection' ` event of a server.
173188
174- ` net.Socket ` instances are EventEmitters with the following events:
175-
176189#### new net.Socket([ options] )
177190
178191Construct a new socket object.
@@ -212,7 +225,7 @@ event.
212225#### socket.bufferSize
213226
214227` net.Socket ` has the property that ` socket.write() ` always works. This is to
215- help users get up an running quickly. The computer cannot necessarily keep up
228+ help users get up and running quickly. The computer cannot always keep up
216229with the amount of data that is written to a socket - the network connection simply
217230might be too slow. Node will internally queue up the data written to a socket and
218231send it out over the wire when it is possible. (Internally it is polling on
@@ -225,7 +238,7 @@ written, but the buffer may contain strings, and the strings are lazily
225238encoded, so the exact number of bytes is not known.)
226239
227240Users who experience large or growing ` bufferSize ` should attempt to
228- "throttle" the data flows in their program with ` pause() ` and resume()`.
241+ "throttle" the data flows in their program with ` pause() ` and ` resume() ` .
229242
230243
231244#### socket.setEncoding(encoding=null)
@@ -260,7 +273,7 @@ event on the other end.
260273
261274#### socket.end([ data] , [ encoding] )
262275
263- Half-closes the socket. I.E ., it sends a FIN packet. It is possible the
276+ Half-closes the socket. i.e ., it sends a FIN packet. It is possible the
264277server will still send some data.
265278
266279If ` data ` is specified, it is equivalent to calling ` socket.write(data, encoding) `
@@ -332,12 +345,13 @@ The amount of received bytes.
332345The amount of bytes sent.
333346
334347
348+ ` net.Socket ` instances are EventEmitters with the following events:
335349
336350#### Event: 'connect'
337351
338352` function () { } `
339353
340- Emitted when a socket connection successfully is established.
354+ Emitted when a socket connection is successfully established.
341355See ` connect() ` .
342356
343357#### Event: 'data'
@@ -377,6 +391,8 @@ See also: `socket.setTimeout()`
377391
378392Emitted when the write buffer becomes empty. Can be used to throttle uploads.
379393
394+ See also: the return values of ` socket.write() `
395+
380396#### Event: 'error'
381397
382398` function (exception) { } `
0 commit comments