From f010419ce9e38fb6bb83bedc2cfa297a9e30030b Mon Sep 17 00:00:00 2001 From: "DESKTOP-B25GA9E\\W35" <1733709035@qq.com> Date: Tue, 14 Mar 2023 17:46:48 +0800 Subject: [PATCH] =?UTF-8?q?TCP=E9=80=9A=E8=AE=AF=E5=8C=85=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86Sender=E8=8E=B7=E5=8F=96=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Example/Script/TCPClientExample.cs | 3 ++- .../TCPClient/Script/TCPClientModel.cs | 4 ++++ .../TCPClient/Script/TCPClientView.cs | 4 ++-- Assets/MsgTransmitTools/src/DataEventModel.cs | 15 +++++++++++++-- 4 files changed, 21 insertions(+), 5 deletions(-) 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