Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: check for errors in listen event #4834

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions doc/api/net.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ var server = net.createServer((socket) => {
});

// grab a random port.
server.listen(() => {
server.listen((err) => {
if (err) throw err;
address = server.address();
console.log('opened server on %j', address);
});
Expand Down Expand Up @@ -528,7 +529,8 @@ Here is an example of a client of the previously described echo server:

```js
const net = require('net');
const client = net.connect({port: 8124}, () => { //'connect' listener
const client = net.connect({port: 8124}, () => {
// 'connect' listener
console.log('connected to server!');
client.write('world!\r\n');
});
Expand Down Expand Up @@ -581,8 +583,8 @@ Here is an example of a client of the previously described echo server:

```js
const net = require('net');
const client = net.connect({port: 8124},
() => { //'connect' listener
const client = net.connect({port: 8124}, () => {
//'connect' listener
console.log('connected to server!');
client.write('world!\r\n');
});
Expand Down Expand Up @@ -649,15 +651,18 @@ on port 8124:

```js
const net = require('net');
const server = net.createServer((c) => { //'connection' listener
const server = net.createServer((c) => {
// 'connection' listener
console.log('client connected');
c.on('end', () => {
console.log('client disconnected');
});
c.write('hello\r\n');
c.pipe(c);
});
server.listen(8124, () => { //'listening' listener
server.listen(8124, (err) => {
// 'listening' listener
if (err) throw err;
console.log('server bound');
});
```
Expand All @@ -672,7 +677,10 @@ To listen on the socket `/tmp/echo.sock` the third line from the last would
just be changed to

```js
server.listen('/tmp/echo.sock', () => { /* 'listening' listener*/ })
server.listen('/tmp/echo.sock', (err) => {
// 'listening' listener
if (err) throw err;
});
```

Use `nc` to connect to a UNIX domain socket server:
Expand Down