Vlad
Vlad

Reputation: 3171

Can I use blocking TCP Socket.Send in a server loop?

If one of the sockets blocks Send() it can affect other client(s). I am worried about that: does Send() waits for the "delivered" answer? If it is than a remote client can block my server events processing loop by ignoring incoming packets - then I should use BeginSend. But I've measured that BeginSend eats more CPU. So I want to know weather it's acceptable to use blocking Send in the server events loop?

As the MSDN states

The successful completion of a send does not indicate that the data was successfully delivered.

I know that socket can also block when its send buffer becomes filled.

Upvotes: 0

Views: 489

Answers (1)

user207421
user207421

Reputation: 310860

If one of the sockets blocks Send() it can affect other client(s).

Only if your server is single-threaded. Solution: multi-threading.

I am worried about that: does Send() waits for the "delivered" answer?

No, but it can block if the client isn't reading and the buffers fill up.

If it is than a remote client can block my server events processing loop by ignoring incoming packets - then I should use BeginSend. But I've measured that BeginSend eats more CPU. So I want to know weather it's acceptable to use blocking Send in the server events loop?

No it isn't. Use multi-threading, or non-blocking I/O, or Async I/O if you can overcome your aversion. Your suggestion of 3-4% overhead doesn't sound right to me.

Upvotes: 1

Related Questions