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

                dispatch(msg)
            }
        } catch let error {
            //TODO: betterer
            print("read failed: \(error)")
        }
    }

    func dispatch(_ json: JSON) {
        // TODO: handle err messages
        guard let address = json["address"].string else {
            print("Invalid message, ignoring: \(json)")
            return
        }


            }
        } 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)
    }
