I'm implementing a client-server app using C# Socket
class (with async methods and SocketAsyncEventArgs
Class). i must implement both TCP and UDP functionality.
My usage is sending some Commands in form of Packets from server to client and vise versa using TCP for important commands and UDP for non-important commands.
it's said that Nagle algorithm may cause merging multiple Sends to one Receive for TCP packets so i set NoDelay
for TCP Sockets (though i had never experienced it!)
another problem may be IP fragmentation but i think assembling fragments occurs somewhere before Receive. so it must be safe to send up to 64KB to Send and Receive at once!
My Question:: Can I Assume that every one Receive corresponds to one Send in 100% cases? (I know that One send may cause zero Receive for UDP lost Packets)
My Reason for asking: should I implement 1)Splitting Merged Packets or 2)Merging split Packets in Receive or is there some circumstances that I can safely assume that 100% every One Receive Corresponds to One Send?
P.S: I'm Using Socket.ReceiveAsync
for TCP and Socket.ReceiveFromAsync
for UDP packets.