diff --git a/Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs b/Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs index 15fbc5c..f55c88e 100644 --- a/Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs +++ b/Assets/MsgTransmitTools/Example/Script/TCPClientExample.cs @@ -9,8 +9,9 @@ public class TCPClientExample : MonoBehaviour,ITCPClient void Start() { //注册接收到数据类型事件监听 - this.RegisterMessageEvent(e => { + this.RegisterMessageEvent((e,sender) => { Debug.Log("TestGetMsg:"+e.msg); + Debug.Log("IpAddress:"+sender); //应答 this.sendRequest(new StringRequest("Received!")); //取消接收该数据 diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientModel.cs b/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientModel.cs index b7a4614..5d3b4ce 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientModel.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientModel.cs @@ -105,6 +105,10 @@ namespace JXSoft } return false; } + public override string getSender() + { + return tcpAddress; + } } #region enum diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs b/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs index 98dc24a..e80e716 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/TCPClient/Script/TCPClientView.cs @@ -107,12 +107,12 @@ namespace JXSoft { } public static class TCPClientExtention { - public static IUnRegister RegisterMessageEvent(this ITCPClient self, Action onEvent) where TResponse : IResponse + public static IUnRegister RegisterMessageEvent(this ITCPClient self, Action onEvent) where TResponse : IResponse { return TCPMangerArchitecture.Interface.RegisterEvent(e => { if (e.res.GetType() == typeof(TResponse)) { - onEvent.Invoke((TResponse)e.res); + onEvent.Invoke((TResponse)e.res,e.sender); } }); } diff --git a/Assets/MsgTransmitTools/src/DataEventModel.cs b/Assets/MsgTransmitTools/src/DataEventModel.cs index 9c8ede7..ab8cdb3 100644 --- a/Assets/MsgTransmitTools/src/DataEventModel.cs +++ b/Assets/MsgTransmitTools/src/DataEventModel.cs @@ -28,6 +28,7 @@ namespace JXSoft { } //找到命令后添加命令 mCommandContainer.Get>().setProtocolData(protocolData); + mCommandContainer.Get>().setSender(getSender()); this.SendCommand(mCommandContainer.Get>()); } /// @@ -81,6 +82,10 @@ namespace JXSoft { setLinkState((int)LinkStateDefault.Close); return true; } + + public virtual string getSender() { + return "default"; + } #endregion } @@ -98,6 +103,7 @@ namespace JXSoft { public class ExcuteResponseCommand : AbstractCommand where TResponse : IResponse { public string protocolData; + public string sender; private TResponse response; private Color printColor = Color.white; public ExcuteResponseCommand(TResponse response) @@ -115,13 +121,16 @@ namespace JXSoft { if (response.toProtocolData() != "") { Debug.Log("Received:" + response.toProtocolData() + response.GetType()); } - this.SendEvent(new ResponseMsgEvent(response)); + this.SendEvent(new ResponseMsgEvent(response, sender)); } } public void setProtocolData(string protocolData) { this.protocolData = protocolData; } + public void setSender(string sender) { + this.sender = sender; + } } /// @@ -282,9 +291,11 @@ namespace JXSoft { public struct ResponseMsgEvent { public IResponse res; - public ResponseMsgEvent(IResponse res_) + public string sender; + public ResponseMsgEvent(IResponse res_,string sender_) { res = res_; + sender = sender_; } }; public struct RequestMsgEvent