using System; using System.Collections; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using UnityEngine; public class UDPPrinter : MonoBehaviour { private UDPUtility udpUtil; // Start is called before the first frame update void Start() { udpUtil = new UDPUtility("127.0.0.1", 20000); udpUtil.sendData("hello everyone!"); } // Update is called once per frame void Update() { if (udpUtil != null && !"".Equals(udpUtil.getReceivedValue())) { /*GameObject item = Instantiate(tcpMsgItem, tcpMsgContent); item.GetComponentInChildren().text = tcpUtil.receivedData.Value; this.GetModel().onDataRecived.Invoke(tcpUtil.receivedData.Value);*/ Debug.Log(udpUtil.receivedData.Value); } } private void OnDestroy() { if (udpUtil.reciveT != null && udpUtil.reciveT.ThreadState == ThreadState.Running) { udpUtil.reciveT.Abort(); } } }