         }
         if self.pongTimer != nil {
             self.pongTimer.invalidate()
+        }
+        if self.commTimer != nil {
+            self.commTimer.invalidate()
         }
         connectionDelegate |> { delegate in
             delegate.websocketDidDisconnect(client: self)

        return randomString
    }

    private func sendRequest(requestType: String, resource: String, content: Serializible?) -> Optional<Error> {
        let lastID = getRandomID()
        let request = Request(id: lastID, requestType: requestType, resource: resource, content: content)
        if self.lastID != nil {
            let now = DispatchTime.now()
            let elapsed = now.uptimeNanoseconds - (lastIDTime?.uptimeNanoseconds)!
            if elapsed > 200000000 {
                print("no response in 200ms")
                pendingRequests.removeValue(forKey: RequestKey(requestType, resource))
                return sendRequest(request: request)
            } else {
                pendingRequests[RequestKey(requestType, resource)] = request
            }
            return .none
        } else {
            return sendRequest(request: request)
        }
    }

    private func sendRequest(request: Request) -> Optional<Error> {
        self.lastID = request.id
        self.lastIDTime = DispatchTime.now()
        switch self.serializer.serializeToString(request) {
        case let .Value(json):
            socket.write(string: json)
            return .none
        case let .Error(error): return error
        }
    }

}

    private var socket: WebSocket!
    private var pingTimer: Timer!
    private var pongTimer: Timer!
    private var commTimer: Timer!
    private var pendingRequests: Dictionary<RequestKey, Request> = [:]
    private var lastID: String? = nil

    var connectionDelegate = MulticastDelegate<WebSocketConnectionDelegate>()
    var communicationDelegate = MulticastDelegate<WebSocketCommunicationDelegate>()
