using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using QFrameworkCP; using System.Threading; namespace JXSoft { public class TCPPrinter : MonoBehaviour,IController { private TCPUtility tcpUtil; public Transform tcpMsgContent; public GameObject tcpMsgItem; void Awake() { tcpUtil = GetArchitecture().GetUtility(); } // Update is called once per frame void Update() { //Debug.Log(tcpUtil.Read_TCPClient()); if (tcpUtil != null && !"".Equals(tcpUtil.getReceivedValue())) { GameObject item = Instantiate(tcpMsgItem, tcpMsgContent); item.GetComponentInChildren().text = tcpUtil.receivedData; this.GetModel().onDataRecived.Invoke(tcpUtil.receivedData); } if (tcpUtil.getTimeOutState() && tcpUtil.isOpenTCP) { this.SendEvent(new onLinkException(tcpUtil.exceptionData)); tcpUtil.isOpenTCP = false; } } private void OnDestroy() { if (tcpUtil.reciveT != null && tcpUtil.reciveT.ThreadState == ThreadState.Running) { tcpUtil.reciveT.Abort(); } } public IArchitecture GetArchitecture() { return TCPMangerArchitecture.Interface; } } }