public override async void SendMessageAsync(INetworkMessage netMsg) { IRemotePeer tmpPeer; if (peerDict.TryGetValue(netMsg.Conv, out tmpPeer)) { UdpClientPeer peer = tmpPeer as UdpClientPeer; UdpNetMessage udpNetMsg = netMsg as UdpNetMessage; var result = peer.EncodeMessage(ref udpNetMsg); if (result) { if (udpSocket != null) { try { var buffer = udpNetMsg.GetBuffer(); int length = await udpSocket.SendAsync(buffer, buffer.Length, peer.PeerEndPoint); if (length != buffer.Length) { //消息未完全发送,则重新发送 SendMessageAsync(udpNetMsg); } } catch (Exception e) { Utility.Debug.LogError($"Send net message exceotion : {e.Message}"); } } } } }
public override void SendMessage(INetworkMessage netMsg) { if (!Available) { return; } UdpNetworkMessage udpNetMsg = netMsg as UdpNetworkMessage; var result = peer.EncodeMessage(ref udpNetMsg); if (result) { SendMessage(udpNetMsg, serverEndPoint); } else { Utility.Debug.LogError("INetworkMessage 消息编码失败"); } }