Open liaoyuzh opened 4 years ago
Yes, that's correct. This is what happens with TCP, it just bundles multiple packages into one. I don't think you can split those messages into the original packages without any extra layer on top of it. The splitting thing is also noted in the todo section. I would be happy to see a pull request from you if you got a solution for the task 👍
Other than that, if you want to get the exact messages you sent you can use UDP with send (which is not blocking, so it won't stall your thread). Using Async with UDP is tricky, you would need to wait for the last package to be received again.
I think for a general solution with TCP a simple message protocol with information of how long each message is would be a smart way to do. On the other hand, that message protocol should be optional, since there are certainly use cases in which it is not needed or in which the protocol has too much overhead for the specific use case.
@JohannesDeml Does setting TCP_NODELAY to true will have the same effect? if you call SendAsync() multiple times in a function.
I haven't tried it, but I would imagine that it is still merging some messages. Do you have time to test that? Otherwise maybe @chronoxor knows, how his library behaves in this case?
@JohannesDeml I tried disabling "Nagle's algorithm" results are same
Hello, I am using your api to build my own network, really good job first of all.
The question is whenever I call SendAsync() multiple times in a function. The code seems to put them all in one buffer as a whole and send it, instead of sending individual buffer at a time. What happens is when my terminal receive an incoming buffer, it tries to parse it and understand the string. So sending it as one giant buffer really causes problem. Without digging too much into the code, it would be great if you could provide some simple solutions! thanks