 
     ///Connect to the websocket server on a background thread
     public func connect() {
+        if isCreated {
+            return
+        }
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), {
+            self.isCreated = true
             self.createHTTPRequest()
+            self.isCreated = false
         })
     }
     

    private var outputStream: NSOutputStream?
    private var isRunLoop = false
    private var connected = false
    private var writeQueue: NSOperationQueue?
    private var readStack = Array<WSResponse>()
    private var inputQueue = Array<NSData>()

        if writeQueue != nil {
            writeQueue!.waitUntilAllOperationsAreFinished()
        }
        if let stream = inputStream {
            stream.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
            stream.close()
        }
        if let stream = outputStream {
            stream.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
            stream.close()
        }        
        outputStream = nil
        isRunLoop = false
