TCP Sockets Best Practise

HI all,
Im currently developing a client-server project using TCP.
But I am facing certain problems.

My Client has 10 Functions each of function send large chunks of data and must able to be sent asyc.
So heres the problem.
While I use Function 1 only to the server is ok and able to process the data. But when I send Function 2 and 1 at the same time heres the problem Data will be mixed and when received my server unable to process.

I did use like start token and end token for each function to differentiate the functions but sometimes it will come in mixed between.
S= Start Token
E= End Token
Client Sent--------------------------------------> Server
----------->

Something like this, how would one use TCP socket to send multiple data only using 1 socket available to send data asyc.

Thanks

That shouldn’t happen. How are you sending the data? Are you using a ServerSocket on the server side? Are you using more than one socket on the client side?

make sure you send the whole packets in one chunk.
That way the order of bytes is stable.
Each package needs to have markers for begin and end unless you use the Easy Sockets in Xojo which do that for you.

If you truly want them to be a sync and be able to send at the same time, you may want to look into using a ServerSocket. That way, each function has their own socket and the data doesn’t get mixed.