public override void OnGet(HttpRequest request, HttpResponse response) { if (request.Upgrade == null || request.Upgrade.Trim().ToLower() != "websocket") { response.Send(); return; } lock (objLock) { if (IsOnSurveillance)//已经用客户端连接了 { response.SetContent("False"); //response.SetContent(JsonConvert.SerializeObject(hit)); //response.SendOnLongConnetion(); response.SendWebsocketData(); response.TcpClient.Close(); StopSurveillance(); //return; } } lock (objLock) { IsOnSurveillance = true; } if (request.RestConvention != null) { Log.Debug(string.Format("准备开始布控任务 布控ID{0}", request.RestConvention)); //根据p.restConvention(taskID)进行 //SurveillanceTask task = ; } HitAlertService.response = response; int id = -1; try { id = Convert.ToInt32(request.RestConvention); } catch { return; } if (!Init(id)) {//开启监控失败 Log.Debug("开启布控任务失败"); response.SetContent("False"); response.SendWebsocketData(); response.TcpClient.Close(); IsOnSurveillance = false; return; } ; byte[] buffer = new byte[1024]; FrameType type = FrameType.Continuation; while (type != FrameType.Close) { int length = 0; if (response.TcpClient.Connected) { length = response.TcpClient.Client.Receive(buffer);//等待客户端的数据,主要等待客户端发送关闭数据 } byte[] data = new byte[length]; Array.Copy(buffer, data, length); type = Hybi13Handler.GetFrameType(new List <byte>(data)); //FRSServerHttp.Server.Websocket.Hybi13Handler.ReceiveData(new List<byte>(data), readState); } StopSurveillance(); }