title: swift socket io connects to server but manager and engine are being released
body: <p>I am trying to make an super basic swift app that connects to my node backend socket.io server but when I run the following code I get a long error, which can be seen below. On the backend, it says that the app connected to the server, but when I try to emit any events, I get another error which is also below.</p>
  
  <p><strong>swift code:</strong></p>
  
  <pre><code>import UIKit
  import SocketIO
  
  class ViewController: UIViewController {
  
  @IBOutlet weak var messagesBody: UITextView!
  @IBOutlet weak var newMessageInput: UITextField!
  @IBOutlet weak var newMessageSubmit: UIButton!
  
  var socket:SocketIOClient!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let manager = SocketManager(socketURL: URL(string: "http://localhost:3000/chat.html?name=developer&amp;room=test")!, config: [.log(true), .compress])
      self.socket = manager.socket(forNamespace: "/")
  
      establishSocketConnection()
  
      newMessageSubmit.addTarget(self, action: #selector(sendNewMessage), for: .touchUpInside)
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  func establishSocketConnection() {
      self.socket.connect()
      self.socket.on("connect") { ( dataArray, ack) -&gt; Void in
          print("connected to external server")
      }
  }
  
  func cloesSocketConnection() {
      self.socket.disconnect()
  }
  
  @objc func sendNewMessage() {
      let newMessageContent = newMessageInput.text!
      print("Sending message..." + newMessageContent)
      self.socket.emit("createMessage", newMessageContent)
  }
  }
  </code></pre>
  
  <p><strong>main error:</strong></p>
  
  <pre><code>2018-02-07 17:53:33.809954-0500 chat-app[78163:6477441] [MC] Lazy 
  loading NSBundle MobileCoreServices.framework
  2018-02-07 17:53:33.811229-0500 chat-app[78163:6477441] [MC] Loaded 
  MobileCoreServices.framework
  2018-02-07 17:53:33.915820-0500 chat-app[78163:6477441] LOG 
  SocketIOClient{/swift}: Handling event: statusChange with data: 
  [connecting]
  2018-02-07 17:53:33.916535-0500 chat-app[78163:6477441] LOG 
  SocketIOClient{/swift}: Joining namespace /swift
  2018-02-07 17:53:33.918305-0500 chat-app[78163:6477441] LOG 
  SocketManager: Tried connecting socket when engine isn't open. 
  Connecting
  2018-02-07 17:53:33.918627-0500 chat-app[78163:6477441] LOG 
  SocketManager: Adding engine
  2018-02-07 17:53:33.921886-0500 chat-app[78163:6477498] LOG 
  SocketEngine: Starting engine. Server: http://localhost:3000/chat.html?
  name=developer&amp;room=test
  2018-02-07 17:53:33.922020-0500 chat-app[78163:6477498] LOG 
  SocketEngine: Handshaking
  2018-02-07 17:53:33.922060-0500 chat-app[78163:6477441] LOG 
  SocketIOClient{/swift}: Adding handler for event: connect
  2018-02-07 17:53:33.922966-0500 chat-app[78163:6477441] LOG 
  SocketManager: Manager is being released
  2018-02-07 17:53:33.924349-0500 chat-app[78163:6477498] LOG 
  SocketEnginePolling: Doing polling GET 
  http://localhost:3000/socket.io/?transport=polling&amp;b64=1
  2018-02-07 17:53:34.014299-0500 chat-app[78163:6477498] LOG 
  SocketEnginePolling: Got polling response
  2018-02-07 17:53:34.016531-0500 chat-app[78163:6477498] LOG 
  SocketEnginePolling: Got poll message: 
  97:0{"sid":"DRRfs3CyuXRDeYVIAAAA","upgrades":
  ["websocket"],"pingInterval":25000,"pingTimeout":60000}
  2018-02-07 17:53:34.022590-0500 chat-app[78163:6477498] LOG 
  SocketEngine: Got message: 0{"sid":"DRRfs3CyuXRDeYVIAAAA","upgrades":
  ["websocket"],"pingInterval":25000,"pingTimeout":60000}
  2018-02-07 17:53:34.045912-0500 chat-app[78163:6477498] LOG 
  SocketEngine: Writing poll:  has data: false
  2018-02-07 17:53:34.046635-0500 chat-app[78163:6477498] LOG 
  SocketEnginePolling: Sending poll:  as type: 2
  2018-02-07 17:53:34.048335-0500 chat-app[78163:6477498] LOG 
  SocketEnginePolling: Created POST string: 1:2
  2018-02-07 17:53:34.049790-0500 chat-app[78163:6477498] LOG 
  SocketEnginePolling: POSTing
  2018-02-07 17:53:34.050572-0500 chat-app[78163:6477498] LOG 
  SocketEngine: Engine is being released
  </code></pre>
  
  <p><strong>second error:</strong></p>
  
  <pre><code>2018-02-07 17:53:37.918418-0500 chat-app[78163:6477441] LOG 
  SocketIOClient{/swift}: Handling event: error with data: ["Tried 
  emitting createMessage when not connected"]
  </code></pre>