日期:2014-05-18  浏览次数:21056 次

Socket服务端程序自动关闭
虽然不是经常出现,但服务端程序偶尔会自动退出。。不知道是什么原因造成的,有朋友遇到过吗?

------解决方案--------------------
调试时经常遇到这种可能性,这对于服务端的调试正常。

可以在Program中写
C# code
        static Program()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ss = string.Format("{0}发生系统异常。\r\n{1}\r\n\r\n\r\n", DateTime.Now, e.ExceptionObject.ToString());
            File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "系统异常.log"), ss);
        }

------解决方案--------------------
如果是这个错误,明显是服务端代码有Bug

查一下,是不是有什么地方,把这个StateObject.BUFFER_SIZE的值改了。
------解决方案--------------------
handler.BeginReceive(state.buffer, 0, state.buffer.Length, 0, out errorCode, new AsyncCallback(ReadCallback), state);