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

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

问题描述

这些错误在我的游戏服务器上越来越频繁.他们导致服务器不断关闭和重新启动...

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)

这是产生这些错误的代码:

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() + "

" + e.Message + "

Stack: " + e.StackTrace + Environment.NewLine + "

";
        File.AppendAllText(Environment.CurrentDirectory + "\data\fatal.txt", WhatToWrite);
        Program.Stop();
    }
}

缓冲区大小设置正确,我们在套接字上使用了 KeepAlive,并使用了发送和接收超时.

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:我们支持 DDoS 缓解服务,这可能会限制连接数...

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

这是一个样板错误消息,它来自 Windows.底层错误代码是 WSAECONNABORTED.这实际上并不意味着连接被中止".你必须对你的主机"有点小心.短语的一部分.在绝大多数 Windows 应用程序中,确实是桌面应用程序所连接的主机中止了连接.通常是其他地方的服务器.

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 end 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.

除非您了解线路另一端发生的情况,否则您真的不知道为什么连接被中止.这当然很难得到.如果您的服务器可以通过 Internet 访问,那么请不要忽视端口扫描程序正在探测您的可能性.或者您的客户,正在寻找游戏作弊.

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天全站免登陆