title: Swift create socket client with GCDAsyncSocket
body: <p>How to create a socket client with GCDAsyncSocket using swift langauge.
  I use following code:</p>
  
  <pre><code>class MySocketClient: GCDAsyncSocketDelegate{
  let addr = "192.168.131.218"
  let port :UInt16 = 8000
  var inp :NSInputStream?
  var out :NSOutputStream?
  var bsocket: GCDAsyncSocket!
  var err :NSError?
  
  func initClient(name: String) -&gt;String{
      bsocket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
      return "init result:"+name
  }
  
  func connect(){
      if(!bsocket.connectToHost(addr, onPort: port, error: nil)){
          println("Error.")
      }else{
          println("Connecting...")
  
      }
  }
  }
  </code></pre>
  
  <p>But it is strange, the result of </p>
  
  <blockquote>
    <p>bsocket.connectToHost(addr, onPort: port, error: nil)
    always return true.</p>
  </blockquote>
  
  <p>No matter I change the ip address or port which are not available.</p>
  
  <p>Why? And what is the right way to create a socket client, and use it to receive/send data to server?</p>