using System.Collections; using System.Collections.Generic; using UnityEngine; using JXSoft; public class TCPClientExample : MonoBehaviour,ITCPClient { // Start is called before the first frame update void Start() { //注册接收到数据类型事件监听 this.RegisterMessageEvent(e => { Debug.Log("TestGetMsg:"+e.msg); //应答 this.sendRequest(new StringRequest("Received!")); //取消接收该数据 this.offReceive(); }); //开启开数据类型接收 this.onReceive(); } } #region ResReqData public class YourResponse : AbstractJsonResponse { public string msg; public YourResponse() { this.msg = ""; } } public struct YourNumberFilterResponse : IResponse { public string code; private int codeNum; private string exceptionMsg; public string toProtocolData() { return "你想要打印的调试信息,无需打印返回空字符串即可"; } public bool trySetData(string protocolData) { bool isNumber = int.TryParse(code, out codeNum); if (!isNumber) { exceptionMsg = "这不是数字"; } return isNumber; } public string getException() { return exceptionMsg; } } public class YourRequest:IRequest { public string toProtocolData() { return "要发的请求内容"; } } #endregion