Receive will throw exception if the connect is disconnected?

mc 4,476 Reputation points
2023-11-10T00:53:54.8233333+00:00

if(socket.Connected)

{

socket.Send(buffer);

}

if the client is closed or disconnected socket.Send will throw an exception .how to avoid this?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,841 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,553 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 65,131 Reputation points
    2023-11-10T01:11:08.4233333+00:00

    You can’t. Until the send is attempted, the status of the connection is unknown.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.