|
@ -1,41 +1,33 @@ |
|
|
|
|
|
using EC.Utils; |
|
|
using EC.Utils.ZMQ; |
|
|
using EC.Utils.ZMQ; |
|
|
|
|
|
using Fleck; |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Text; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using EC.Utils; |
|
|
|
|
|
using Fleck; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ECMonitor.Manager |
|
|
namespace ECMonitor.Manager |
|
|
{ |
|
|
{ |
|
|
public class WebSocketManager |
|
|
public class WebSocketManager |
|
|
{ |
|
|
{ |
|
|
WebSocketServer _webSocketServer = null; |
|
|
private WebSocketServer _webSocketServer = null; |
|
|
List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>(); |
|
|
private List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>(); |
|
|
|
|
|
|
|
|
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
|
|
|
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
|
|
|
public WebSocketManager( ) |
|
|
|
|
|
|
|
|
public WebSocketManager() |
|
|
{ |
|
|
{ |
|
|
FleckLog.Level = LogLevel.Debug; |
|
|
FleckLog.Level = LogLevel.Debug; |
|
|
|
|
|
|
|
|
_webSocketServer = new WebSocketServer("ws://0.0.0.0:"+ ConfigHelper.WebSocketSvrPort()); |
|
|
_webSocketServer = new WebSocketServer("ws://0.0.0.0:" + ConfigHelper.WebSocketSvrPort()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Start() |
|
|
public void Start() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
_webSocketServer.Start(socket => |
|
|
_webSocketServer.Start(socket => |
|
|
{ |
|
|
{ |
|
|
socket.OnOpen = () => |
|
|
socket.OnOpen = () => |
|
|
{ |
|
|
{ |
|
|
// Console.WriteLine("Open!");
|
|
|
// Console.WriteLine("Open!");
|
|
|
allSockets.Add(socket); |
|
|
allSockets.Add(socket); |
|
|
}; |
|
|
}; |
|
|
socket.OnClose = () => |
|
|
socket.OnClose = () => |
|
@ -47,16 +39,17 @@ namespace ECMonitor.Manager |
|
|
{ |
|
|
{ |
|
|
//Console.WriteLine(message);
|
|
|
//Console.WriteLine(message);
|
|
|
// allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
|
|
|
// allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
|
|
|
WebSocketDataReceived(socket,message); |
|
|
WebSocketDataReceived(socket, message); |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Stop() |
|
|
public void Stop() |
|
|
{ |
|
|
{ |
|
|
allSockets.ToList().ForEach(s => s.Close()); |
|
|
allSockets.ToList().ForEach(s => s.Close()); |
|
|
_webSocketServer.Dispose(); |
|
|
_webSocketServer.Dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void WebSocketDataReceived(object sender, string message) |
|
|
private void WebSocketDataReceived(object sender, string message) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
@ -70,12 +63,10 @@ namespace ECMonitor.Manager |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch(Exception ex) { |
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
LogFactory.GetLogger().Error(ex); |
|
|
LogFactory.GetLogger().Error(ex); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |