title: how to connect socket in iOS Swift?
body: <p>I am trying to connect socket using api with token and namespace. It showing error <strong>Tried connecting socket when engine isn't open. Connecting, Error during long poll request</strong></p>
  
  <p>Here is my code for socket:</p>
  
  <pre><code>  import UIKit
    import SocketIO
  
  class SocketIOManager: NSObject {
  
  static let authToken = UserDefaults.standard.string(forKey: "authToken")
  static let bearerToken: String = "Bearer " + (authToken ?? "")
  static let newBaseURL = UserDefaults.standard.string(forKey: "baseURL")!
  //static let v = newBaseURL + "/event-stream/?token=\(bearerToken)"
  
  static let v = newBaseURL
  
  
  
  static let manager = SocketManager(socketURL: URL(string: v)!, config: [.log(true), .compress, .forcePolling(false), .forceNew(true), .reconnects(true), .reconnectAttempts(100), .forceWebsockets(true)])
  static let socket = manager.socket(forNamespace: "/event-stream/")
  
  
  
  class func connectSocket(){
      self.manager.config = SocketIOClientConfiguration(
          arrayLiteral: .connectParams(["token": SocketIOManager.bearerToken]), .secure(true)
      )
      socket.connect()
  }
  
  class func disconnectSocket(){
      socket.disconnect()
     }
   }
  </code></pre>
  
  <p>here is my error log:</p>
  
  <pre><code>    2020-01-27 15:05:36.607140+0530 A8FlowSampleApp[1517:468209] LOG SocketIOClient{/event- stream/}: Handling event: statusChange with data: [connecting, 2]
      2020-01-27 15:05:36.607465+0530 A8FlowSampleApp[1517:468209] LOG SocketIOClient{/event- 
     stream/}: Joining namespace /event-stream/
      2020-01-27 15:05:36.607579+0530 A8FlowSampleApp[1517:468209] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
      2020-01-27 15:05:36.607653+0530 A8FlowSampleApp[1517:468209] LOG SocketManager: Adding engine
     2020-01-27 15:05:36.612981+0530 A8FlowSampleApp[1517:468391] LOG SocketEngine: Starting engine. Server: api url
    2020-01-27 15:05:36.613238+0530 A8FlowSampleApp[1517:468391] LOG SocketEngine: Handshaking
    2020-01-27 15:05:36.635760+0530 A8FlowSampleApp[1517:468391] LOG SocketEnginePolling: Doing polling GET https://api url/socket.io/?transport=polling&amp;b64=1&amp;token=Bearer%20eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhOGZsb3ciLCJleHAiOjE1ODAyNzcyNzAsInVzZXJuYW1lIjoiZGVtbyJ9.SaoWMoYF-bp57fEXw0-EJAW9JDQZ8fyaYjCirL06M1Y
    2020-01-27 15:05:36.990748+0530 A8FlowSampleApp[1517:468395] ERROR SocketEnginePolling: Error during long poll request
   2020-01-27 15:05:36.990925+0530 A8FlowSampleApp[1517:468395] ERROR SocketEngine: Error
   2020-01-27 15:05:36.991075+0530 A8FlowSampleApp[1517:468209] ERROR SocketManager: Error
  </code></pre>
  
  <p>Any help much appreciated pls....</p>