# Inter-App Communication

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:

```csharp
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:

```csharp
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:

```csharp
Discv5Protocol discv5 = new Discv5Builder()
                        .WithConnectionOptions(connectionOptions)
                        .WithSessionOptions(sessionOptions)
                        .WithTableOptions(tableOptions)
                        .WithBootstrapEnrs(bootstrapEnrs)
                        .WithEnrBuilder(enrBuilder)
                        .WithEnrEntryRegistry(enrEntryRegistry)
                        .WithLoggerFactory(loggerFactory)
                        .WithTalkResponder(customHandler) // Custom handler
                        .Build();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://piertwo.gitbook.io/lantern.discv5/usage/inter-app-communication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
