Closed lablnet closed 6 months ago
import io.libp2p.core.Host
import io.libp2p.core.dsl.host
import io.libp2p.core.multiformats.Multiaddr
import io.libp2p.protocol.Ping
fun main() {
val port = 12345
val host:Host = host{
identity {
random()
}
network {
listen("/ip4/127.0.0.1/tcp/${port}")
}
protocols {
+ Ping()
}
}
host.start().get()
val remote = Multiaddr("/ip4/127.0.0.1/tcp/${port}/p2p/${host.peerId}")
val ping = Ping().dial(host, remote).controller.get()
println("Sending 5 ping messages to $remote")
for(i in 0 until 5){
val latency = ping.ping().get()
println("ping $i latency: ${latency}ms")
}
host.stop().get()
}
I am looking for documentation, too. I need to do a lot more than ping, and I am using Java.
The library contains a lot of functionality but unfortuality lacking the documentation.
Can anyone help me how I can implement PING in Kotlin?
The example given is for Java.
Another help would be good how to write 4 functions, subscribe to topic, unsubscribe to topic, sendMsgToTopic, ReciveMsgOnTopic.