Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from libp2p/fix/examples
Update examples
- Loading branch information
Showing
5 changed files
with
59 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Echo client/server with libp2p | ||
|
||
This example can be started in either listen mode (server), or dial mode (client). | ||
|
||
In listen mode, it will sit and wait for incoming connections on | ||
the `/echo/1.0.0` protocol. Whenever it receives a stream, it will | ||
write whatever message it received, and close the stream. | ||
|
||
In dial mode, it will connect to the target peer on the given address. | ||
It then opens a stream, writes a short message on the same protocol, | ||
and print whatever reply it receives. | ||
|
||
## Build | ||
|
||
``` | ||
> make deps | ||
> go build ./examples/hosts | ||
``` | ||
|
||
## Usage | ||
|
||
In one terminal: | ||
|
||
``` | ||
> ./hosts -l 4737 | ||
2016/11/06 04:37:00 I am /ip4/127.0.0.1/tcp/4737/ipfs/QmXzbaXtBw6mU29WoeYrCtcRLVbT8asWCcEFVuDy4w6pdq | ||
2016/11/06 04:37:00 listening for connections | ||
2016/11/06 04:37:01 got a new stream | ||
2016/11/06 04:37:01 read request: "Hello, world!" | ||
``` | ||
|
||
In another, copy the address printed by the listener and do: | ||
|
||
``` | ||
> ./hosts -d /ip4/127.0.0.1/tcp/4737/ipfs/QmXzbaXtBw6mU29WoeYrCtcRLVbT8asWCcEFVuDy4w6pdq | ||
2016/11/06 04:37:01 I am /ip4/127.0.0.1/tcp/0/ipfs/QmeMNYMmkgoyd8M7y925r4yVVDjKtiYtU4rNCyj7wDWzk1 | ||
2016/11/06 04:37:01 connecting to target | ||
2016/11/06 04:37:01 opening stream | ||
2016/11/06 04:37:01 read reply: "Hello, world!" | ||
> | ||
``` |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.