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.

Thanks!

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.

@jacobheun
This is a good question and I want to know how can send an arbitrary message to a peer that we know? Through pubsub.

Imagine a new (node_N) joins to the network. His state is S_0. He propagates his state through pubsub network. The other nodes receive his state and now they try to help him to catch up by sending some data. In this case, other nodes can simply send message to node_N.

Any better idea?