You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
49 lines
1.5 KiB
2 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Events;
|
||
|
using UnityEngine.UI;
|
||
|
using QFramework;
|
||
|
using System.Threading;
|
||
|
|
||
|
namespace TCPClientTools
|
||
|
{
|
||
|
public class TCPPrinter : MonoBehaviour,IController,ICanSendEvent
|
||
|
{
|
||
|
private TCPUtility tcpUtil;
|
||
|
public Transform tcpMsgContent;
|
||
|
public GameObject tcpMsgItem;
|
||
|
|
||
|
void Awake()
|
||
|
{
|
||
|
tcpUtil = GetArchitecture().GetUtility<TCPUtility>();
|
||
|
}
|
||
|
|
||
|
// 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>().text = tcpUtil.receivedData.Value;
|
||
2 years ago
|
this.GetModel<TCPEventModel>().onDataRecived.Invoke(tcpUtil.receivedData.Value);
|
||
2 years ago
|
}
|
||
|
if (tcpUtil.getTimeOutState() && tcpUtil.isOpenTCP) {
|
||
|
this.SendEvent(new onLinkException(tcpUtil.exceptionData.Value));
|
||
|
tcpUtil.isOpenTCP.Value = false;
|
||
|
}
|
||
|
}
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
if (tcpUtil.reciveT != null && tcpUtil.reciveT.ThreadState == ThreadState.Running) {
|
||
|
tcpUtil.reciveT.Abort();
|
||
|
}
|
||
|
}
|
||
|
public IArchitecture GetArchitecture()
|
||
|
{
|
||
|
return TCPMangerArchitecture.Interface;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|