C#中已建立的连接是通过软件在主机中止 [英] C# An established connection was aborted by the software in your host machine

查看:433
本文介绍了C#中已建立的连接是通过软件在主机中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些错误是越来越频繁的我游戏服务器上。他们使服务器保持关闭和重启...

System.Net.Sockets.SocketException(0X80004005):一个已建立的连接是通过软件在主机中止
   在System.Net.Sockets.Socket.BeginSend(字节[]缓冲区,偏移的Int32,的Int32大小,的SocketFlags的SocketFlags,AsyncCallback的回调,对象状态)
   在iRP.Game.Sessions.Session.SendData(字节[]数据)已建立的连接是通过软件在主机中止堆栈:在System.Net.Sockets.Socket.BeginSend(字节[]缓冲区,偏移的Int32,的Int32大小,的SocketFlags的SocketFlags,AsyncCallback的回调,对象的状态)
   在iRP.Game.Sessions.Session.SendData(字节[]数据)

这是从产生这些错误的code:

 公共无效送出数据(字节[]数据)
{
    尝试
    {
        如果(mSocket == NULL)
        {
            //Output.WriteLine(\"[SND]插孔具有空异常,这意味着现在作废删除此套接字,OutputLevel.CriticalError)!;
        }
        其他
        {
            mSocket.BeginSend(数据,0,Data.Length,SocketFlags.None,sendCallback,mSocket);
        }
    }
    赶上(例外五)
    {
        字符串WhatToWrite =错误处理(会话):+ e.ToString()+\\ n \\ n+ e.Message +\\ n \\ nStack:+ e.StackTrace + Environment.NewLine +\\ n \\ n
        File.AppendAllText(Environment.CurrentDirectory +\\\\ \\\\数据fatal.txt,WhatToWrite);
        Program.Stop();
    }
}

该缓冲区的大小设置正确,我们正在使用的插座连接的存活用发送和接收超时。

人建议禁用防火墙会有所帮助,但每当我做到这一点我们的游戏服务器(专用服务器)重新启动本身,如果是受到攻击,因此防火墙必须保持启用状态。

其他任何人有任何其他的方案来解决这个?

PS:我们是DDoS攻击防护服务,这可能会限制连接数的背后...


解决方案

  

这是建立的连接被软件在主机中止


这是一个样板式的错误信息,它出来的Windows。根本的错误code为WSAECONNABORTED。这并不代表不是连接被中止了。你必须要小心一点关于这句话的您的主机的一部分。在大多数Windows应用程序,这的确是该桌面应用程序连接到中止连接的主机。通常,服务器在其他地方。

该角色颠倒但是当你实现你自己的服务器。现在,你需要读作在另一导线的应用程序中止的错误消息。当你实现一个服务器,当然并不少见,使用你的服务器的客户端程序并非不可能中止无论出于何种原因的连接。它的可以的意思是火墙或代理终止连接,但是这不太可能,因为它们通常不会允许首先要建立的连接。

您真的不知道为什么一个连接被中止,除非你有深入了解是什么在导线的另一端​​回事。这当然很难得的。如果您的服务器通过互联网可达那么不打折,你正在一个端口扫描器探测的可能性。或您的客户,寻找一个游戏作弊。

These errors are getting more and more frequent on my Game Server. They are causing the server to keep closing and restarting...

System.Net.Sockets.SocketException (0x80004005): An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
   at iRP.Game.Sessions.Session.SendData(Byte[] Data)

An established connection was aborted by the software in your host machine

Stack:    at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
   at iRP.Game.Sessions.Session.SendData(Byte[] Data)

This is the code from which these errors are generated:

public void SendData(byte[] Data)
{
    try
    {
        if (mSocket == null)
        {
            //Output.WriteLine("[SND] Socket has a null exception, which means it is now invalid. Remove this socket!", OutputLevel.CriticalError);
        }
        else
        {
            mSocket.BeginSend(Data, 0, Data.Length, SocketFlags.None, sendCallback, mSocket);
        }
    }
    catch (Exception e)
    {
        string WhatToWrite = "Error handled (SESSION): " + e.ToString() + "\n\n" + e.Message + "\n\nStack: " + e.StackTrace + Environment.NewLine + "\n\n";
        File.AppendAllText(Environment.CurrentDirectory + "\\data\\fatal.txt", WhatToWrite);
        Program.Stop();
    }
}

The buffer sizes are correctly set, we are using KeepAlive on the socket and were using Send and Receive Timeouts.

People suggested that disabling the firewall would help, but whenever I do this our Game Server (Dedicated Server) restarts itself as if it's under attack, so the firewall must remain enabled.

Anyone else got any other solutions for this?

PS: We are behind DDoS Mitigation Services which may be limiting the number of connections...

解决方案

An established connection was aborted by the software in your host machine

That is a boiler-plate error message, it comes out of Windows. The underlying error code is WSAECONNABORTED. Which really doesn't mean more than "connection was aborted". You have to be a bit careful about the "your host machine" part of the phrase. In the vast majority of Windows application programs, it is indeed the host that the desktop app is connected to that aborted the connection. Usually a server somewhere else.

The roles are reversed however when you implement your own server. Now you need to read the error message as "aborted by the application at the other of the wire". Which is of course not uncommon when you implement a server, client programs that use your server are not unlikely to abort a connection for whatever reason. It can mean that a fire-wall or a proxy terminated the connection but that's not very likely since they typically would not allow the connection to be established in the first place.

You don't really know why a connection was aborted unless you have insight what is going on at the other end of the wire. That's of course hard to come by. If your server is reachable through the Internet then don't discount the possibility that you are being probed by a port scanner. Or your customers, looking for a game cheat.

这篇关于C#中已建立的连接是通过软件在主机中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆