If going for the first option from your post, what is the best/correct way to (keep) sync with synapse ?
...
Are CanWite and CanRead helpful there when situated at the correct locations, or .. ?
A smaller buffer on client side wouldn't matter in case of tcp. The communication will wait until the buffer is processed. So mixing raw data and strings shouldn't matter if everything goes well. Of course, when there is packetloss it can become quite chaotic then
In that case opening a second socket for raw file transfer would be the better option. On sending side opening the socket for listening and waiting for connection and on the receiving side connecting to that. After that the sending side can just stuff the complete file on the wire. On the receiving side it will end up in the file specified earlier by the string-socket communication (like the @PUT,filename,1234,5678).
In that case the raw data socket is only used for the actual filedata transfer and stays 'clean'. And there is no raw data on the string-socket. Also, the string-socket can continue sending and receiving data during file transport.
Further communications (like @CONFIRM,filename,1234,5678) from the receiving end that the file is received correctly etc is indeed up to the yet to be defined protocol.
Edit:
I would use 1kb local buffer and write that to a tfilestream.