title: How to connect to websocket in swift?
body: <p>I am trying to create a connection to web socket with a link ws://link.net:8888/ws?token= to open communication with the server.</p>
  
  <p>I found out that I could use Stream but I don't know how to add access_token to the end.</p>
  
  <pre><code>    Stream.getStreamsToHost(withName: host, port: port, inputStream: &amp;inputStream, outputStream: &amp;outputStream)
  
      if inputStream != nil &amp;&amp; outputStream != nil {
  
          // Set delegate
          inputStream!.delegate = self
          outputStream!.delegate = self
  
          // Schedule
          inputStream!.schedule(in: .main, forMode: RunLoopMode.defaultRunLoopMode)
          outputStream!.schedule(in: .main, forMode: RunLoopMode.defaultRunLoopMode)
          print("Start open()")
  
          // Open!
          inputStream!.open()
          outputStream!.open()
      }
  </code></pre>
  
  <p>And for some reason even if I try to connect to link without access key, I am unsuccessful. So does anyone have a way how to open connection to the socket with access_key added I would be very grateful?</p>
  
  <p>I also tried <a href="https://github.com/swiftsocket/SwiftSocket" rel="noreferrer">https://github.com/swiftsocket/SwiftSocket</a> but it also doesn't have an option to add anything on end, the only thing I will try now it is <a href="https://github.com/socketio/socket.io-client-swift" rel="noreferrer">https://github.com/socketio/socket.io-client-swift</a>.</p>
  
  <p>EDIT1:
  So after a comment from Dan Karbayev I checked out Starscream with code</p>
  
  <pre><code>let url = "ws://link.net:5000/ws?token=token"
  let socket = WebSocket(url: URL(string: url)!)
  socket.onConnect = {
      print("websocket is connected")
  }
  //websocketDidDisconnect
  socket.onDisconnect = { (error: Error?) in
      print("websocket is disconnected: \ 
  (error?.localizedDescription)")
  }
  //websocketDidReceiveMessage
  socket.onText = { (text: String) in
      print("got some text: \(text)")
  }
  //websocketDidReceiveData
  socket.onData = { (data: Data) in
       print("got some data: \(data.count)")
  }
  //you could do onPong as well.
  socket.connect()
  </code></pre>
  
  <p>But for some odd reason none of socket methods don't wake up.</p>
  
  <p>EDIT 2:</p>
  
  <p>At the end I ended using <a href="https://github.com/tidwall/SwiftWebSocket" rel="noreferrer">https://github.com/tidwall/SwiftWebSocket</a>.
  It worked right away.</p>
  
  <p>But thanks to all for help.</p>