I am using GCDAsyncSocket
to create a TCP client on iOS (using swift). The client is communicating with a TCP server written in JAVA. The data is written to to the socket using the JAVA's writeUtf()
method. So to read the data on the TCP client, I need to know the length of the data available on the socket. The java UTF format is different from standard UTF and encodes the length of the content in first 2 bytes of data. The length of the incoming data must be known to read the data in GCDAsyncSocket.
Questions:
How to get the size of incoming data from the first two bytes of modified UTF-8 in swift?
Is there any better way to read the data from java writeUTF() by detecting the end of the stream?