This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs): Update readme.md's example and added files for it
- Loading branch information
Showing
3 changed files
with
111 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
const tcp = require('net') | ||
const pull = require('pull-stream') | ||
const toPull = require('stream-to-pull-stream') | ||
const multiplex = require('../src') | ||
|
||
const socket = tcp.connect(9999) | ||
|
||
const muxer = multiplex.dialer(toPull(socket)) | ||
|
||
console.log('[dialer] opening stream') | ||
const stream = muxer.newStream((err) => { | ||
console.log('[dialer] opened stream') | ||
if (err) throw err | ||
}) | ||
|
||
pull( | ||
pull.values(['hey, how is it going. I am the dialer']), | ||
stream | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const tcp = require('net') | ||
const pull = require('pull-stream') | ||
const toPull = require('stream-to-pull-stream') | ||
const multiplex = require('../src') | ||
|
||
const listener = tcp.createServer((socket) => { | ||
console.log('[listener] Got connection!') | ||
|
||
const muxer = multiplex.listener(toPull(socket)) | ||
|
||
muxer.on('stream', (stream) => { | ||
console.log('[listener] Got stream!') | ||
pull( | ||
stream, | ||
pull.drain((data) => { | ||
console.log('[listener] Received:') | ||
console.log(data.toString()) | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
listener.listen(9999, () => { | ||
console.log('[listener] listening on 9999') | ||
}) |