How to run app ?
go build
Run in first terminal ./chat
Run in second terminal ./chat -d (use multi address printed on first terminal)
Concepts related to p2p chat :
- we should append \n for every message as we are using it as delimiting character while reading it.
- S.close() used for closing stream.
- once a stream is opened , the object of stream should be used again and again untill it is closed. thats why we use for loop to stay on same stream for chat.
- In order to speak to other peer , our peer should add the multiaddress of first peer to its peer table.