         logger.error("Did not publish Bonjour service: \(errorDict)")
     }
 }
+
+extension ChannelPipeline {
+    func addHapClientHandlers(application: ChannelHandler, controller: ChannelHandler) -> EventLoopFuture<Void> {
+        addHandler(CryptographerHandler()).flatMap {
+            self.addHandler(EventHandler()).flatMap {
+                self.configureHTTPServerPipeline(withErrorHandling: true).flatMap {
+                    self.addHandler(controller).flatMap {
+                        self.addHandler(RequestHandler()).flatMap {
+                            self.addHandler(UpgradeEventHandler()).flatMap {
+                                self.addHandler(application)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

        device.controllerHandler = ControllerHandler()
        device.controllerHandler!.removeSubscriptions = device.removeSubscriberForAllCharacteristics

        let applicationHandler = ApplicationHandler(responder: root(device: device))

        self.ownGroup = worker == nil
        self.group = worker ?? MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)


            // Set the handlers that are applied to the accepted child `Channel`s.
            .childChannelInitializer { channel in
                // It's important we use the same handler for all accepted channels.
                // The ControllerHandler is thread-safe!
                channel.pipeline.addHapClientHandlers(application: application, controller: device.controllerHandler!)
            }

            // Enable TCP_NODELAY and SO_REUSEADDR for the accepted Channels
