public static void SendToWebsocket(WebsocketSendObjctBase obj, object websocket_) { WebSocket websocket = (WebSocket)websocket_; string sendjsonStr = Tools.ToolsSerialize.SerializeObjectToJson(obj); if (websocket.State == WebSocketState.Open) { websocket.SendAsync(new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes(sendjsonStr)), WebSocketMessageType.Text, true, CancellationToken.None); } return; }
public static void Send(WebsocketSendObjctBase obj) { string sendjsonStr = Tools.ToolsSerialize.SerializeObjectToJson(obj); if (obj.PlayerId == 0) { foreach (var item in PlayerIdAndWebsockets.Values) { if (item.State == WebSocketState.Open) { item.SendAsync(new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes(sendjsonStr)), WebSocketMessageType.Text, true, CancellationToken.None); } } return; } WebSocket websocket = FindClientWebSocketByPlayerId(obj.PlayerId); if (websocket.State == WebSocketState.Open) { websocket.SendAsync(new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes(sendjsonStr)), WebSocketMessageType.Text, true, CancellationToken.None); } }