Inter-App Communication
This section describes how a custom subprotocol can be implemented for allowing communication between different applications.
To implement a custom subprotocol, this library provides the ITalkReqAndRespHandler
interface that can be inherited into a class containing custom logic. This class can handle application-specific subprotocols using TALKREQ
and TALKRESP
messages. Here is an example of this:
public class CustomHandler : ITalkReqAndRespHandler
{
public byte[]? HandleRequest(byte[] protocol, byte[] request)
{
// Handle the incoming TalkReq request here
// Return response payload or null
}
public byte[]? HandleResponse(byte[] response)
{
// Handle the incoming TalkResp response here
// Return processed response or null
}
}
An instance of CustomHandler
can then be passed as a parameter to the CreateDefault
method:
ITalkReqAndRespHandler customHandler = new CustomHandler();
Discv5Protocol discv5 = Discv5Builder.CreateDefault(bootstrapEnrs, customHandler);
Alternatively, if Discv5Builder
is used, then the instance of CustomHandler
can be passed to it using:
Discv5Protocol discv5 = new Discv5Builder()
.WithConnectionOptions(connectionOptions)
.WithSessionOptions(sessionOptions)
.WithTableOptions(tableOptions)
.WithBootstrapEnrs(bootstrapEnrs)
.WithEnrBuilder(enrBuilder)
.WithEnrEntryRegistry(enrEntryRegistry)
.WithLoggerFactory(loggerFactory)
.WithTalkResponder(customHandler) // Custom handler
.Build();
Last updated