private void DoRecieveCallBack(IAsyncResult ar) { try { IPEndPoint point = new IPEndPoint(IPAddress.Any, 0); byte[] bts = udpClient.EndReceive(ar, ref point); if (MessageRecieved == null) { return; } MessageType type; string str = UnitsHepler.ParseMessage(bts, out type); if (MessageRecieved != null) { MessageRecieved.BeginInvoke(type, str, null, null); } } catch (Exception ex) { // log.Error("读取异常:", ex.Message); } finally { BeginRecieve(); } }
private void DoRecieveCallBack(IAsyncResult ar) { try { IPEndPoint point = new IPEndPoint(IPAddress.Any, 0); byte[] bts = udpClient.EndReceive(ar, ref point); if (MessageRecieved == null) { return; } string str = Encoding.UTF8.GetString(bts); int ind = str.IndexOf('.'); MessageType type = MessageType.NONE; if (ind > 0) { string msgType = str.Substring(0, ind); if (Enum.TryParse <MessageType>(msgType, out type)) { str = str.Substring(ind + 1); } else { type = MessageType.NONE; } } if (MessageRecieved != null) { MessageRecieved.BeginInvoke(type, str, null, null); } } catch (Exception ex) { // log.Error("读取异常:", ex.Message); } finally { BeginRecieve(); } }