Can I use Swallow SocketExceptions in some situations?

Say I programmed an application that connects to a server using the Socket (TCP) class. If I encounter a SocketException while reading or writing, then obviously I need to go ahead and start the disconnect procedure to change the application state to “Disabled”.

But what if I started disconnecting, and while I clean up, a SocketException is raised?

SocketException doesn't really mean anything to me, since I was going to turn off the socket anyway ... is that normal to learn?

I really want to know what is the best practice for this situation.

+3
source share
4 answers

, .net-, WCF.

, , , , , , , .

0

, "" . , (SMTP) () , , Close. , , , .

, .

+2

, . ? , ?

+1
source

If something goes wrong during a shutdown, then what state will the socket be in? In the worst case, the remote socket will time out. In fact, you can do nothing to rectify this situation.

But, as Joe R said, write down the message - these exceptions can also occur because it Disconnect()is called twice, which you want to know about. (Edit: I don’t know if this exception would raise, but I hope you know what I mean: P)

0
source

Source: https://habr.com/ru/post/1745420/


All Articles