Use of Socket.BeginAccept/EndAccept for multiple connections

前端 未结 2 993
甜味超标
甜味超标 2021-01-19 07:57

Unlike the synchronous Accept, BeginAccept doesn\'t provide a socket for the newly created connection. EndAccept however does, but it

2条回答
  •  不知归路
    2021-01-19 08:29

    The way are doing this is correct for using asynchronous sockets. Personally, I would move your BeginAccept to right after you get the socket from the AsyncState. This will allow you to accept additional connections right away. As it is right now, the handling code will run before you are ready to accept another connection.

    As Usr mentioned, I believe you could re-write the code to use await with tasks.

提交回复
热议问题