title: How to read all lines in socket (swift)
body: <p>I have problem to read lines. When server (server code in java) sent more than one line code, my secket can not read all lines.</p>
  
  <p><strong>I used this library</strong> <a href="https://github.com/swiftsocket/SwiftSocket" rel="nofollow">https://github.com/swiftsocket/SwiftSocket</a>
  and socket read method code:</p>
  
  <pre><code>private func sendRequest(data: String, client: TCPClient?) -&gt; (String?) {
      // It use ufter connection
      if client != nil {
          // Send data  (WE MUST ADD TO SENDING MESSAGE '\n' )
          let (isSuccess, errorMessage) = client!.send(str: "\(data)\n")
          if isSuccess {
              // Read response data
              let data = client!.read(1024*10)
              if let d = data {
                  // Create String from response data
                  if let str = NSString(bytes: d, length: d.count, encoding: NSUTF8StringEncoding) as? String {
                      return (data: str)
                  } else {
                      return (data: nil)
                  }
              } else {
                  return (data: nil)
              }
          } else {
              print(errorMessage)
              return (data: nil)
          }
      } else {
          return (data: nil)
      }
  }
  </code></pre>
  
  <p>I have changed like this : <code>let data = client!.read(1024*40)</code> but again can not read (received data large). it read some received data like this:</p>
  
  <pre><code>338C6EAAD0740ED101860EFBA286A653F42793CF1FC7FB55D244C010941BDE3DCA540223B291639D1CD7285B4240B330EBC7C002003F957790749256D54EAC4DB7FC0AD5E2970FE951DFA0A1635A93DFCB031DBA642BA928B8327B661F9F4F22CA657AE803B25A208C23F72D6F934B95558108C1187F90E6D8DE13F9367534E7EC28DBA5AC6C8597800154033B63A3B2185DF68ABF67BB76AC6B593C52E5D7B0A5D7674BEC7C6AA9B4C57343C32C944FEB5D1C2D6C2A400D454196A0029C23DB30F1B6049423DC5BEE728E03C275F207639C25E226A38A23EAE04AD673132336D9E113FC6CA32DAD1D75191BCE40A281D40549C1D6FDD23BC5A38B472ED1EEB6BA1D80D00EF2A08F4729FD05329993A6AE58C34253660A77C20139C73FE0E4A68D9857E02C3F8589A61B22C4E26B3DA00098158FB6CE0C43F271ABC823BF9AD7DBEB32A4E9BE4E90C284E1FD633956F82EB5387DE2E8D7626C88900D183C7E1F683C27B8A654EE75017E897D11F2431A9AB4C0662CC91B3897D52E630A788A1A8D552ABB04916B5E52A1382DB2803A796A96ACC50C00913C650393AA919100E6477B7D88066FEB6C78D4F5853122AB6D7309540053B9DB98BEC0D518CD8BF41620506E1224FB0F8B240B7E9FD60649E703FA9E6A21E785BB0F646DB028F5C5E64697E41A857F6A2A459B2C1B070C244F7B6FD252FFF016CC0A4F0457711213C025E6165706DF6C35C6C38F53610373C3DE99DFE426102860E2D4CD1BF5F6B97346655F0E26103CD6BF37AFCE705D4D2F78F7F40C5316143725D0D7FB6647A92F98A42570F423D646DC2CA726ABB16ED6C62C
  </code></pre>
  
  <p>but not all. How to fix this. Please, advise me. Thanks </p>