         reconnect()
     }
 
-
-}
-
+    public func webSocket(webSocket: SRWebSocket!, didCloseWithCode code: Int, reason: String!, wasClean: Bool) {
+
+        connected = false
+
+        clearSubscriptions()
+
+        let error = NSError(domain: FayeClientWebSocketErrorDomain, code: code, userInfo: [NSLocalizedDescriptionKey: reason])
+        delegate?.fayeClient(self, didDisconnectWithError: error)
+
+        reconnect()
+    }
+}
+


public typealias FayeClientPrivateHandler = (message: FayeMessage) -> Void

public class FayeClient {

    public private(set) var webSocket: SRWebSocket?
    public private(set)var serverURL: NSURL!

        return webSocketClosed
    }

    public override init() {
        super.init()
    }

    public convenience init(serverURL: NSURL) {
