public bool Post(string operate, string ip, int port, int index) { try { if (index > 10 || index < 0) { return(false); } AppFrame app = AppFrame.GetAppFrame(); switch (operate.ToLower()) { case "up": return(!string.IsNullOrEmpty(app.SetUp("Web用户", ip: ip, port: port, index: index))); case "down": return(!string.IsNullOrEmpty(app.SetDown("Web用户", ip: ip, port: port, index: index))); default: return(false); } } catch (Exception) { return(false); } }
public void Get() { var context = this.HttpContext; if (context.WebSockets.IsWebSocketRequest) { ISimpleWebSoket webSoket = new MyWebSoket(context.WebSockets.AcceptWebSocketAsync().Result); webSoket.OnMessage += (o, e) => { Console.WriteLine(e.Data); }; AppFrame app = AppFrame.GetAppFrame(); EventHandler <PLC.ModBus.Rtu.Driver.EventEntity.ParkingLotStatusEventArgs> OnSelected = (o, e) => { webSoket.SendAsync(e.ToString()).Wait(); }; app.OnSelected += OnSelected; webSoket.OnMessage += (o, e) => { webSoket.SendAsync(e.Data); }; webSoket.KeepAlive(); app.OnSelected -= OnSelected; } }