开发者

Client Server (TCP) Question (Time)

I'm relatively new to C# so please bear with me. I'm working on a client server application (in C#, .NET 4.0) and I don't understand some things completely.

Let's assume that there is an established connection between a TCP server and client. Can (without errors) you write to the underlying stream from one endpoint if on the other endpoint read wasn't called yet?

If you can, how much time do you have to call read() and still get all the data? How much data can be in a buffer and how long does it stay in there if there is some sort of a buffer? Which data gets lost if you don't call read for some time (newest, oldest, ... ?)

Can there be problems if you debug both client and server application at the same time, can it happen that connec开发者_高级运维tion seems to be closed because one application is waiting to make a next step in debug mode?

Thank you for your precious time and answers.


Let's assume that there is an established connection between a TCP server and client. Can (without errors) you write to the underlying stream from one endpoint if on the other endpoint read wasn't called yet?

Yes. the OS has an internal buffer for each socket in it's socket implementation. Everything will be stored until that buffer is full.

If you can, how much time do you have to call read() and still get all the data? How much data can be in a buffer and how long does it stay in there if there is some sort of a buffer? Which data gets lost if you don't call read for some time (newest, oldest, ... ?)

It all depends on how large the buffer is and how often the other end point sends data to it. You can use Socket.ReceiveBufferSize to adjust it.

Can there be problems if you debug both client and server application at the same time, can it happen that connection seems to be closed because one application is waiting to make a next step in debug mode?

No. TCP connections are always open unless one of the end points closes it. Please keep in mind that other parts of your code can close the connection if you use asynchronous IO and do not break ALL threads in each application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜