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

Mobile Developer, Just a Christian-Atheist-Palestinian-Israeli-Arab-Gay kinda guy, just the type you could meet anytime.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store