c# - Getting SocketException while calling BeginSend -


I have to type an app that accepts sends incoming and outgoing socket connections and Close some of those data N ms My code:

  Private Readonly Timer _ Assert timer; Private Readonly Socket _ Sarraskett = New Socket (Address Family.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Private Readonly ConcurrentDictionary & lt; Endpoint, socket & gt; _clientConnections = New ConcurrentDictionary & lt; Endpoint, socket & gt; (); Public Start (SettingsProvider settings provider) {_senderTimer = New Timer (SendIntervalTick, blank, Settings provider. SendInterval, Timeout.Infinite); _serverSocket.Bind (new IPPpoint (self imp, self port)); _serverSocket.Listen (MaxLengthOfPendingConnectionsQueue); _serverSocket.BeginAccept (Accept callback, empty); } Accept private zones callback (IAsyncResult result) {endpoint end page = zero; Try {var Approved Socket = _serverSocket.EndAccept (Results); EndPoint = Accepted Socket.RemoteEndPoint; _clientConnections.TryAdd (End Point, Approved Socket); } Hold (Exception e) {CloseSocket (Endpoint); } Finally {_serverSocket.BeginAccept (AcceptCallback, blank); }} Private Zero SendIntervalTick (object state) {SendPacket (new [] {(byte) 0xFF}); _senderTimer.Change (Math, 0, _sendInterval - clock.Ellepeded milliseconds, timeout, infinite);} Private Zero SendPacket (byte [] packet) {var connToRemove = New list & lt; EndPoint & gt; (); var connToSend = _clientConnections.ToDictionary (x = & gt; x.Key, x = & gt; x.Value); // send all packets to affiliate foreach (connToSend in connection) {try to send packet {connection.Value.BeginSend (Packet, 0, packet.Length, SocketFlags.None, SendCallback, New ClientConnection (connection, connection.Value));} Hold (Exception e) {// Get System.Net.Sockets.SocketException (0x80004005): One installed Connection in your host machine The software was aborted from here !!! connToRemove.Add (of connection);}} // Close closed connections foreach (var endPoint in connToRemove) {CloseSocket (endPoint);}} Private Zero SendCallback (IAsyncResult Result) {var connection = (ClientConnection) result. AsyncState; Try {connection.Sock.EndSend (result);} hold (exception e) {CloseSocket (connection.RemoteEndPoint); }} Private Zero LockSockets (Endpoint Endpoint) {Socket SocketTokosaj; Close the _clientConnections.TryGetValue (end point, out sockettoklos) {socketToClose.Close (); SocketToClose.Dispose (); } Hold (exception e) {logger Error ("Error of closing / disposal socket.", E); } Finally {Socket removable; If (! _clientConnections.TryRemove (endpoint, extractable)) {Logger.Warn ("One endpoint ({}} can not be removed from the client connection - dict ({1}).", Endpoint, string.Join (",", _clientConnections.Keys)); }}}  

Now I get an exception

  System.Net.Sockets.SocketException (0x80004005): Rejected by Software in an established connection Sent your host machine  

When the phone starts sending between 20-50 successful send

  trace 674 bytes successfully customer 212.193.xxx.xxx: 21666 sent to trace sent successfully to customer 212.193.xxx: 674 bytes: I have noticed that the exception always throws new connections soon after the throws .xxx: 21666 Debug end point (212.193.xxx.xxx:22014) Successfully added client connection-dict (212.193.xxx.xxx:21666, 212.193.xxx.xxx:22014) Trace 674 bytes successfully Customer 212.193 Sent to .xxx.xxx: 21666 trace 674 bytes successfully sent to customer 212.193.xxx.xxx:22014 due to the exception of socket 212.193.xxx.xxx:21666 when the start alert: System.Net.Sockets.SocketException (0x80004005) : An established connection was aborted by the software in your host machine  

but I I do not know why the error is and how to fix it.

Edit : I sniffed traffic and found out that one of the customers (which is always the problem Was a source of time) from time to time, a reset flag is the reason why I failed to send it to the packet. According to the answer, the server may be due to the closed socket of the closed packet. I wonder why this might happen and how the server should behave in this situation.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -