Sending arbitrary data from one peer to another

I want to simply send a string from one peer to another (they both know each other’s peerinfo) after one dials a protocol which another handles. Is this possible without streaming?

If not what would be the best way to acheive this.


Assuming you want to send a direct message and not send it via pubsub, you’ll need to use the stream from dialProtocol. The data isn’t necessarily streaming, depending on what you’re are doing, but you’re reading/writing to an underlying stream.

Can you clarify your use case a bit more? Do you just want to send a string and then close the stream? Do you want to be able to keep the stream open and send strings back and forth as needed?

There’s a variety of ways to send data via libp2p, as it’s designed to be flexible, so better understanding the data you’re sending and how you intend for the sender/receiver to operate on that data would help me be able to provide a more concrete snippet of code.