Skip to content

Commit

Permalink
update old example code
Browse files Browse the repository at this point in the history
  • Loading branch information
Halimao committed Dec 29, 2023
1 parent d877b21 commit ce041aa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/chat-with-mdns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ func handleStream(stream net.Stream) {

3. **Find peers nearby using mdns**

Start [mdns discovery](https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#NewMdnsService) service in host.
New [mdns discovery](https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#NewMdnsService) service in host.

```go
ser, err := discovery.NewMdnsService(peerhost, rendezvous)
notifee := &discoveryNotifee{PeerChan: make(chan peer.AddrInfo)}
ser, err := discovery.NewMdnsService(peerhost, rendezvous, notifee)
```
register [Notifee interface](https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#Notifee) with service so that we get notified about peer discovery

```go
n := &discoveryNotifee{}
ser.RegisterNotifee(n)
ser.Start()
```



4. **Open streams to peers found.**

Finally we open stream to the peers we found, as we find them
Expand Down

0 comments on commit ce041aa

Please sign in to comment.