private void SendDataAsync(WebSocket socket, Messages.IMessage message) { using (var buffer = bufferManager.GetBuffer()) { int msgLen = message.ToBytes(buffer.Buffer); socket.SendAsync(new Memory <byte>(buffer.Buffer, 0, msgLen), WebSocketMessageType.Binary, true, CancellationToken.None); Interlocked.Add(ref bytesSent, msgLen); } }
private void BroadcastMessage(Messages.IMessage message) { using (var buffer = bufferManager.GetBuffer()) { int msgLen = message.ToBytes(buffer.Buffer); var mem = new Memory <byte>(buffer.Buffer, 0, msgLen); foreach (var player in Players) { player.Value.Socket.SendAsync(mem, WebSocketMessageType.Binary, true, CancellationToken.None); Interlocked.Add(ref bytesSent, msgLen); } } }