title: Tcp communication in swift
body: <p>I want to exchange data between iPad and an embedded device through TCP. 
  I am using the TCP frame work <a href="https://github.com/robbiehanson/CocoaAsyncSocket" rel="nofollow noreferrer">CocoaAsyncSocket</a>. 
  Using this i created a client and server which are actually two different ipads. </p>
  
  <p>I am able to connect from the client to the server by giving the servers ip address to the client and the delegate for accepting the new connection is getting called on the server. </p>
  
  <p>But i am not able to write any data from client to server also i need to do it vice versa be able to write and read from server to client. </p>
  
  <p>Have used the below code for writing from client to server. </p>
  
  <pre><code>//Client side
  //For making a connection with server, this is succesfull
  func establishSocket() {
  
      do {
  
      try socket!.connect(toHost: "192.168.xx.xxx", onPort: 5007)
      }
      catch {
          print("Could not connect to host")
      }
  
  }
  //this is to write data to the server. 
  func writeString(message:String) {
      let data = message.data(using: .utf8)
      socket?.write(data!, withTimeout: -1, tag: 1)
  }
  
  
  //Server side
  //This is called succesfully
  func socket(_ sock: GCDAsyncSocket, didAcceptNewSocket newSocket: 
  GCDAsyncSocket) {
      print("Did accept on socket")
      setSocketRead()
  }
  
  func setSocketRead() {
  serverSocket?.readData(to: reaaddata, withTimeout: -1, tag: 1)
  }
  
  //This is not getting called
  func socket(_ sock: GCDAsyncSocket, didRead data: Data, withTag tag: 
  Int) {
      let datastring = data.base64EncodedString()
      print(datastring)
  }
  </code></pre>
  
  <p>If you know the correct flow please help me out. </p>
  
  <p>Thanks</p>