using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; using UnityEngine; using QFrameworkCP; namespace JXSoft { public class HttpServerArchitecture : Architecture { protected override void Init() { this.RegisterUtility(new HttpServerUtility()); this.RegisterModel(new HttpServerModel()); } } public class HttpServerView : MonoBehaviour,IController { public string[] prefixes; public HttpServerUtility httpServer; // Start is called before the first frame update void Start() { this.httpServer = this.GetUtility(); this.RegisterMessageEvent(e => { Debug.Log("收到消息:"+e.ip); }).UnRegisterWhenGameObjectDestroyed(gameObject); this.GetModel().onReceive(); } // Update is called once per frame void Update() { if (httpServer != null && !"".Equals(httpServer.getReceivedValue())) { /*GameObject item = Instantiate(tcpMsgItem, tcpMsgContent); item.GetComponentInChildren().text = tcpUtil.receivedData; this.GetModel().onDataRecived.Invoke(tcpUtil.receivedData); */ this.GetModel().onDataRecived.Invoke(httpServer.receivedData); } } public void startServer() { bool isSuccess = httpServer.startServer(prefixes); Debug.Log("ServerOpen:"+isSuccess); } private void OnDestroy() { httpServer.closeServer(); } public IArchitecture GetArchitecture() { return HttpServerArchitecture.Interface; } } }