--

It mostly depends on your server-side.

My own server-side sends 4 bytes firstly (as an int as the string bytes length) and then the whole string.

The "readIntFrom(stream)" function reads only 4 bytes exactly, to know in advance how many bytes to read (as a string) in the "readStringFrom(stream,withSize)" function.

If your server acts differently, you must find a creative way to react to the exact data sent from it (ex: if you already know the bytes length sent from the server, you can remove the "readIntFrom(stream)" function and pass the "readStringFrom(stream, withSize)" function.

Otherwise, you can set up your server to send:

(bytesLength: UInt32 as "4" bytes),

and then (string: String as "bytesLength" bytes).

--

--

Pierre Janineh
Pierre Janineh

Written by Pierre Janineh

Embracing Best Practices in the Tech Landscape | PierreJanineh.com

Responses (1)