Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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);
                }
            }
        }