public void Send(string channelName, int ContractID, Dictionary <string, string> sendParams, Action <object> callback = null, bool loadMask = true) { var channel = this.Channels[channelName]; var body = CreateBody(sendParams); var signStr = channel.Pipeline.ClientID + channel.Pipeline.SessionID + ContractID + body.Length.ToString(); var sign = GetCrypt(channel.Options.key).EncryptECB(signStr); var message = MessageFactory.Create(channel.Pipeline.ClientID, channel.Pipeline.SessionID, ContractID, sign, body) as RequestMessagePacket; if (callback != null) { var action = ActionFactory.CreateAction.Invoke(channelName, ContractID); action.Params = sendParams; action.Callback = callback; this.SendActions.Add(message.MessageID, action); } if (this.SendCallBack != null) { //当前不一定是主线程,,得添加到loom中 //loom是在update内执行(不是立即)。。确保这里是顺序执行 Loom.QueueOnMainThread(() => { SendCallBack.Invoke(channel.Pipeline, message, loadMask); channel.Pipeline.WriteAndFlushAsync(message); }); } else { channel.Pipeline.WriteAndFlushAsync(message); } }
/// <summary> /// 向客户端发送数据 /// </summary> public void SendData(object msg) { var data = this.Encoding.GetBytes((string)msg); try { _client.Send(data); SendCallBack?.Invoke(TheEndPoint); } catch { } }
public void Update() { sendCb.Invoke(e, data, data.Length); }