/// <summary> /// 广播发送信息给房间内所有玩家 /// </summary> /// <param name="socket"></param> public void Brocast(SocketMsg socket, ClientPeer exClient = null) { byte[] data = EncodeHelper.EncodeMsg(socket); byte[] packet = EncodeHelper.EncodePacket(data); foreach (var client in UIdClientDict.Values) { if (client == exClient) { continue; } client.Send(packet); } }
/// <summary> /// 广播 /// </summary> /// <param name="room"></param> /// <param name="socketMsg"></param> /// <param name="client"></param> private void BroCast(FightRoom room, SocketMsg socketMsg, ClientPeer client = null) { byte[] data = EncodeHelper.EncodeMsg(socketMsg); byte[] packet = EncodeHelper.EncodePacket(data); foreach (var user in room.playerList) { ClientPeer clientPeer = UserCache.GetClient(user.UserId); if (clientPeer == null || clientPeer == client) { continue; } clientPeer.Send(packet); } }
/// <summary> /// 发送消息 /// </summary> /// <param name="msg"></param> public void Send(SocketMsg msg) { byte[] data = EncodeHelper.EncodeMsg(msg); byte[] packet = EncodeHelper.EncodePacket(data); try { socket.Send(packet); } catch (Exception e) { Debug.LogError(e.Message); throw; } }
/// <summary> /// 发送数据 /// </summary> /// <param name="msg"></param> public void Send(SocketMsg msg) { //if (!socket.Connected) //{ // Connect(); //} byte[] data = EncodeHelper.EncodeMsg(msg); byte[] packet = EncodeHelper.EncodePacket(data); try { socket.Send(packet); } catch (Exception e) { Debug.LogError(e.Message); } }