/// <summary> /// 写入消息尝试Socket异常和消息类型 /// </summary> /// <param name="ex">套接字错误消息</param> /// <param name="msgType">消息类型</param> public void Write(SocketException ex, MessageType msgType) { Write(string.Format("{0}[{1}]", ex.SocketErrorCode, ex.ErrorCode), msgType); Write(ex.GetType().Name, msgType); Write(ex.Message, msgType); Write(ex.StackTrace, msgType); Write(ex.Source, msgType); }
public void ReadStreamMessage(IAsyncResult ar) { if (!ar.IsCompleted) { return; } int _intCount; try { if (!this.m_TcpClient.Connected) { this.Disconnect(); return; } _intCount = this.m_Stream.EndRead(ar); if (_intCount < 1) { this.Disconnect(); return; } byte[] _recByte = (byte[])ar.AsyncState; this.BuildText(_recByte, 0, _intCount); if (this.m_ConnectionState == ConnectionState.NotConnected) { return; } lock (this.m_Stream) { this.Listen(); } } catch (IOException _ex) { if (_ex.InnerException != null && _ex.InnerException is SocketException) { SocketException _socketException = (SocketException)_ex.InnerException; this.Disconnect(_socketException); if (_socketException.SocketErrorCode != SocketError.ConnectionReset) { Console.WriteLine("{0}: {1}", _socketException.GetType().ToString(), _socketException.Message); } } else { this.Disconnect(); Console.WriteLine("{0}: {1}", _ex.GetType().ToString(), _ex.Message); } } }
private static bool handleSocketException(SocketException ex, MethodBase Method) { Logging.Logger("ERROR: MethodName=" + Method.Name + " Type: " + ex.GetType().Name + " #:" + ex.SocketErrorCode + " Message:" + ex.Message); switch (ex.SocketErrorCode) { //FTPSocket timeout case SocketError.TimedOut: //10060 PromptUser("Lost connection to the server or the server took too long to respond. See Log. '" + Paths.LogPath + "'", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Network Socket Timeout"); return(true); case SocketError.HostUnreachable: //10065 'host unreachable return(true); case SocketError.ConnectionAborted: //10053 PromptUser("Lost connection to the server or the server took too long to respond. See Log. '" + Paths.LogPath + "'", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Connection Aborted"); return(true); case SocketError.ConnectionReset: //10054 'connection reset PromptUser("Lost connection to the server or the server took too long to respond. See Log. '" + Paths.LogPath + "'", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Connection Reset"); return(true); case SocketError.NetworkUnreachable: PromptUser("Could not connect to server. See Log. '" + Paths.LogPath + "'", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Network Unreachable"); return(true); case SocketError.HostNotFound: //11001 'host not found. return(false); default: UnHandledError(ex, (int)ex.SocketErrorCode, Method); return(false); } }
private static string GetMessage(SocketException ex) { var errors = new StringBuilder(); errors.AppendLine(); #if DEBUG errors.AppendLine($"[{ex.GetType().Name}]"); #endif switch (ex.ErrorCode) { // Maximum request length exceeded case 10060: errors.AppendLine("ارتباط با سرور، به دلیل عدم پاسخگویی سرور، وجود ندارد"); break; default: errors.AppendLine($"{ex.ErrorCode}: {ex.Message}"); break; } return(errors.ToString()); }
static void Log(SocketException ex) { CallLog("[Server Exception]" + ex.GetType().Name + "|" + ex.SocketErrorCode + ":" + ex.Message + "\n" + ex.StackTrace); }
void Log(SocketException ex) { NetworkSystem.CallLog("[Client Exception:" + port + "]" + ex.GetType().Name + "|" + ex.SocketErrorCode + ":" + ex.Message + "\n" + ex.StackTrace); }