I found these 2 working code example to receive data from android:
- TWinSocketStream.Read(): Read error 6, The handle is invalid
- Error to receive file on socket inside a thread
where seems that is suggested use two separated sockets in each side (2 on sender and 2 on receptor). One to handle text data and other to handle image data respectively.
I also found this C# code (see Client code), where after an adaptation i was able to receive text and image using only 1 socket:
var _strdata = String.Empty;
// ...
// then on 2º while loop i adapted to also receive text
if (read <= 0)
break;
bytesRead += read;
_strdata += Encoding.UTF8.GetString(_bindata, 0, read);
// and after
if (_strdata.Contains("<|data|>"))
receivedMessage(client, _strdata); // text
else if (_strdata.Contains("<|screen|>"))
receivedImage(client, _bindata); // image
Then i ask: How i can have a hybrid Delphi code to receive text and image with only one socket connection?