public void Working(ReceiveEventHandler receive = null) { FleckLog.Level = LogLevel.Debug; allSockets = new List <IWebSocketConnection>(); server = new WebSocketServer("ws://0.0.0.0:7066"); server.RestartAfterListenError = true; server.Start(socket => { socket.OnOpen = () => { allSockets.Add(socket); OnOpen?.BeginInvoke(socket, null, null); }; socket.OnClose = () => { allSockets.Remove(socket); OnClose?.BeginInvoke(socket, null, null);//通知断开 }; socket.OnMessage = message => { receive?.BeginInvoke(message, socket, null, null); }; socket.OnError = ex => { OnError?.BeginInvoke(ex, socket, null, null); }; }); }
private void open() { try { if (!IsOpen) { port.Open(); if (IsOpen) { OnOpen?.BeginInvoke(null, null); } } } catch (Exception ex) { raiseError(ComPortErrorNames.OnOpen, ex); } }