title: how to use socket in swift (connect, send and get message)
body: <p>I am new swift. I want to make chat for iphone so i need to use client sokect. how to make this. give me advise or example  plz.
  I tried this
  <a href="https://github.com/socketio/socket.io-client-swift" rel="noreferrer">https://github.com/socketio/socket.io-client-swift</a>
  but not connected
  and tried this code</p>
  
  <pre><code> let client:TCPClient = TCPClient(addr: "89.236.254.27", port: 9000)
       let (success,errmsg) = client.connect(timeout: 1)
       if success {
            let (success,errmsg) = client.send(str:"Hello World!")
            if success {
                 let data = client.read(1024 * 10)
                 if let d = data {
                      if let str = NSString(bytes: d, length: d.count, encoding: NSUTF8StringEncoding) {
                           print(str)
                      }
                 }
            } else {
                 print(errmsg)
            }
       } else {
            print(errmsg)
       }
  </code></pre>
  
  <p>after change this code:</p>
  
  <pre><code> override func viewDidLoad() {
       super.viewDidLoad()
  
       let qualityOfServiceClass = QOS_CLASS_BACKGROUND
       let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
       dispatch_async(backgroundQueue, {
           let client:TCPClient = TCPClient(addr: "89.236.254.27", port: 9000)
           var (success, errmsg)=client.connect(timeout: 1)
           if success {
               var (isSuccess, errorMessage) = client.send(str: "Hello!")
               if success {
                   let data = client.read(1024 * 4)
                   if let d = data {
                       if let str = NSString(bytes: d, length: d.count, encoding: NSUTF8StringEncoding) as? String {
                           print(str)
                       }
                   }
               } else {
                   print(errmsg)
               }
           } else {
               print(errmsg)
           }
           dispatch_async(dispatch_get_main_queue(), { 
              () -&gt; Void in
              print("This is run on the main queue, after the previous code in outer block")
           })
       })
   }
  </code></pre>