         } else {
             self.handlers[address] = [_id : handler]
         }
-        
+
         try send(JSON(["type": "register", "address": address])) //TODO: headers
 
         return _id

    public func unregister(address: String, id: String) throws -> Bool {
        guard var handlers = self.handlers[address],
              let _ = handlers[id] else {
                          
            return false
        }

        handlers.removeValue(forKey: id)

        if handlers.isEmpty {
            try send(JSON(["type": "unregister", "address": address])) //TODO: headers
        }
            
        return true
    }

              
    public func close() {
        if self.open {
            self.socket.close()

            }
        } else if let h = self.replyHandlers[address] {
            workQueue.async(execute: { h(json) })
        }
    }

    func send(_ message: JSON) throws {
        try Util.write(from: message, to: self.socket)
    }

    func send(_ message: String) throws {
        try Util.write(from: message, to: self.socket)
    }
