C# Stream.Beginsend

Asked

Viewed 58 times

1

As you can see in the link below, the Streamreceiver method uses the Beginread method to read asynchronously, whereas the Senddata method does not use asynchronous writing, which is the logic to read asynchronously and write synchronously?

To obtain a good performance, being that the flow of reading and writing data would be practically equivalent, Beginsend should be used to write also asynchronously?

http://wiki.unity3d.com/index.php/Simple_TCP/IP_Server_Code

1 answer

0


Depends on the size of the buffer. You read or write asynchronously when you want to take advantage of the available CPU cycles while you wait for information to be transferred over the network.

In your example, it would make sense if writing is small and reading is a ton of things. So that between the callback response of Beginread is giant.

Now, if both are large buffers, it doesn’t make sense how it’s implemented.

On my blog (http://ericlemes.com) has some things about asynchronous I/O that can help you understand the difference.

  • Instead of pointing to your Blog, paste the contents of the archive here. Because the link to your Blog may become unavailable over time. Thanks for wanting to help, and I hope you’re not taking it personally, but that’s how Sopt works(As far as I can tell)!

  • Martian, no personal side :-). I understand politics. But I think the reverse is true. If I paste the content you have and the entire implementation of a socket server here, or more detailed work on the internet, it will be unreadable. The same when someone references a msdn documentation. Should we paste the whole original? On the other hand, I understand that the question has been answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.