| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,27 +35,26 @@ Here is an example of a echo server which listens for connections | |||
| 35 | 35 | on port 8124: | |
| 36 | 36 | ||
| 37 | 37 | 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); | ||
| 50 | 41 | }); | |
| 51 | 42 | server.listen(8124, 'localhost'); | |
| 52 | 43 | ||
| 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 | ||
| 54 | 49 | changed to | |
| 55 | 50 | ||
| 56 | 51 | server.listen('/tmp/echo.sock'); | |
| 57 | 52 | ||
| 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: | ||
| 59 | 58 | ||
| 60 | 59 | #### server.listen(port, [host], [callback]) | |
| 61 | 60 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments