Why socket reads 0 bytes when more was available

后端 未结 1 959
無奈伤痛
無奈伤痛 2020-12-19 05:32

I discovered that the following code loops with 100% CPU usage:

byte[] buffer = new byte[0x10000];
while (true) {
    if (socket.Poll (5000000, SelectMode.Se         


        
相关标签:
1条回答
  • 2020-12-19 06:35

    Have you read the documentation?

    0 bytes read means that the remote end point have disconnected.

    Either use blocking sockets or use the asynchronous methods like BeginReceive(). There is no need for Poll in .Net.

    0 讨论(0)
提交回复
热议问题