How to break socket in c #

I am trying to disconnect a socket so that the client from the other end will receive "WSAECONNABORTED (10053) software that caused the connection to fail." error message while polling a connection.

Close () and Shutdown () will be disabled gracefully. I do not want a graceful separation. I want to make Abort so that the client feels that something really went wrong.

Thanks,

EDIT: I am encoding a server and I want to abort sockets to connect clients.

+6
c # sockets
source share
6 answers

I managed to simulate this situation:

Make a normal graceful shutdown:

:

socket.Shutdown(SocketShutdown.Both); socket.Close(); 

However, to do Abort, you do:

 socket.Shutdown(SocketShutdown.Send); socket.Close(); 

I think the difference is that the client will not receive any ACK packets and thinks that the computer is reset or something.

+2
source share

The basic information is described in detail below, including when it is really necessary to force an interruption of the connection, described here ( fooobar.com/questions/16439 / ... ).

C # Method:

 socket.LingerState = new LingerOption(true, 0); socket.Close(); 

That is, use SO_LINGER with TIME_WAIT = 0

+2
source share

What if you kill the process and / or restart the computer and / or disconnect the Ethernet cable without calling Close () and / or Shutdown ()?

+1
source share

I don’t think you can get the behavior you need using the .Net Socket implementation, except that the client sends intermittent keep-alives. I tried all kinds of things to describe the behavior you described and completed the implementation of keep-alive messages. If the sever call calls Close (), the client socket will receive a connection abort error the next time it sends data.

0
source share

try calling EndSend () or EndReceive () depending on the situation immediately followed by Dispose ()

-one
source share

you can try to encode all secondary sockets in another thread and kill it when you want connection failure.

-one
source share

All Articles