> For the complete documentation index, see [llms.txt](https://piertwo.gitbook.io/lantern.discv5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://piertwo.gitbook.io/lantern.discv5/usage/inter-app-communication.md).

# 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();
```
