nim-libp2p icon indicating copy to clipboard operation
nim-libp2p copied to clipboard

Add streaming protocol tutorial, fix tutorial #2 early conn termination

Open emizzle opened this issue 2 years ago • 6 comments

Add a tutorial that shows how to create a streaming protocol.

In the second tutorial, the connection was being terminated too quickly in main, before the server had a chance to echo. By adding a connection read on the client side (in hello), we wait for the server to echo the message it received and respond back before closing the connection.

~~NOTE: This PR is based on the branch fix/switch-start-return-futs from PR #662. That PR should likely be merged first, then we can rebase this branch on top of unstable.~~

emizzle avatar Nov 26 '21 01:11 emizzle

You can also add a link to your tutorial at the end of the second one, and add it to the CI in libp2p.nimble

Fixed up.

Also changed the way the stream checks atEof using readOnce instead of readLp and adjusted the comments and tutorial explanation to suit.

emizzle avatar Dec 01 '21 06:12 emizzle

Updated tutorial 3 (streaming tutorial) to remove readLp/writeLp in combo with atEof, and instead using write, readOnce, and atEof.

emizzle avatar Dec 02 '21 11:12 emizzle

I think 90% of users will use the Lp variants, but since we already show it in tutorial 2, it may make sense to show the non-Lp here But it should be clear that Lp can of be used for streaming as well, since it's about what everybody does

Menduist avatar Dec 02 '21 11:12 Menduist

I think 90% of users will use the Lp variants, but since we already show it in tutorial 2, it may make sense to show the non-Lp here But it should be clear that Lp can of be used for streaming as well, since it's about what everybody does

I'll make tutorial #3 a streaming tutorial with readLp/writeLp and LPStreamEOFError, then we can make a fourth with read/write and atEof.

emizzle avatar Dec 03 '21 00:12 emizzle

Should've updated this sooner, added a fourth tutorial as per above comment.

emizzle avatar Dec 07 '21 11:12 emizzle

Is there anything blocking this? LGTM

dryajov avatar Jan 14 '22 18:01 dryajov