FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Simplify the net.Server example in docs · reado/node@a3c91c2 · GitHub

Repository navigation

Commit a3c91c2

Browse files
committed
Simplify the net.Server example in docs
1 parent 9a7fb3c commit a3c91c2

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

‎doc/api/net.markdown‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,26 @@ Here is an example of a echo server which listens for connections
3535
on port 8124:
3636

3737
var net = require('net');
38-
var server = net.createServer(function (stream) {
39-
stream.setEncoding('utf8');
40-
stream.on('connect', function () {
41-
stream.write('hello\r\n');
42-
});
43-
stream.on('data', function (data) {
44-
stream.write(data);
45-
});
46-
stream.on('end', function () {
47-
stream.write('goodbye\r\n');
48-
stream.end();
49-
});
38+
var server = net.createServer(function (c) {
39+
c.write('hello\r\n');
40+
c.pipe(c);
5041
});
5142
server.listen(8124, 'localhost');
5243

53-
To listen on the socket `'/tmp/echo.sock'`, the last line would just be
44+
Test this by using `telnet`:
45+
46+
telnet localhost 8124
47+
48+
To listen on the socket `/tmp/echo.sock` the last line would just be
5449
changed to
5550

5651
server.listen('/tmp/echo.sock');
5752

58-
This is an `EventEmitter` with the following events:
53+
Use `nc` to connect to a UNIX domain socket server:
54+
55+
nc -U /tmp/echo.sock
56+
57+
`net.Server` is an `EventEmitter` with the following events:
5958

6059
#### server.listen(port, [host], [callback])
6160

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL