public void Write(UserToken token, byte type, int area, int command, object message) { //消息体的编码 byte[] value = MessageEncoding.MessageEncode(CreateSocketModel(type, area, command, message)); //长度编码,因为在服务器传入的时候进行了长度编码,所以在处理的时候也要进行长度编码 value = LengthEncoding.Encode(value); token.Write(value); }
public void Brocast(byte type, int area, int command, object message, UserToken exToken = null) { byte[] value = MessageEncoding.MessageEncode(CreateSocketModel(type, area, command, message)); value = LengthEncoding.Encode(value); foreach (UserToken item in userList) { if (item == exToken) { continue; } byte[] bs = new byte[value.Length]; //防治将元数据变更 Array.Copy(value, 0, bs, 0, value.Length); item.Write(bs); } }
public void WriteToUsers(int[] users, byte type, int area, int command, object message) { byte[] value = MessageEncoding.MessageEncode(CreateSocketModel(type, area, command, message)); value = LengthEncoding.Encode(value); foreach (int item in users) { UserToken token = userBiz.GetToken(item); if (token == null) { continue; } byte[] bs = new byte[value.Length]; //防治将元数据变更 Array.Copy(value, 0, bs, 0, value.Length); token.Write(bs); } }