Q: How to flush CocoaAsyncSocket? Is there a way to flush the internal buffers/queues/etc. of CocoaAsyncSocket (GCDasyncSocket)?
I want to setup the environment that when I call the [... readDataWithTimeout ..] method, I don't want it to read any left over garbage data from a previous connection that might have been buffered and sitting somewhere.
Or sometimes I just want to ignore a stream of data and start over, so want to ensure a clean pipe.

A: I've also asked this question in the CocoaAsyncSocket Google Group and Robbie Hanson was kind enough to elaborate with his answer.

A: Make sure you send \n or \r after you write data.
I have write a socket manager class you can check it here: CocoaAsyncSocketManager
Sample code: 
func sendMessage(messageString msg: String) {
    if let _data = msg.data(using: .utf8), let _carriageReturn = "\r".data(using: .utf8) {
        tcpSocket?.write(_data, withTimeout: -1, tag: 0)
        tcpSocket?.write(_carriageReturn, withTimeout: -1, tag: 99)
    }
}

