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 { [Header("WebUrl")] public string[] prefixes; // Start is called before the first frame update void Start() { startServer(); } // Update is called once per frame void Update() { if (this.GetUtility().httpServer != null && !"".Equals(this.GetUtility().getReceivedValue())) { this.GetModel().onDataRecived.Invoke(this.GetUtility().receivedData); } } public void startServer() { this.GetModel().setPrefixes(prefixes); bool isSuccess = this.GetModel().Start(); Debug.Log("ServerOpen:"+isSuccess); } private void OnDestroy() { this.GetModel().Close(); } public IArchitecture GetArchitecture() { return HttpServerArchitecture.Interface; } } public interface IHttpServer { } public static class HttpServerExtention { public static IUnRegister RegisterMessageEvent(this IHttpServer self, Action onEvent) where TResponse : IResponse { return HttpServerArchitecture.Interface.RegisterEvent(e => { if (e.res.GetType() == typeof(TResponse)) { onEvent.Invoke((TResponse)e.res); } }); } public static void onReceive(this IHttpServer self) where TResponse : IResponse,new() { HttpServerArchitecture.Interface.GetModel().onReceive(); } public static void offReceive(this IHttpServer self) where TResponse : IResponse, new() { HttpServerArchitecture.Interface.GetModel().offReceive(); } } }