コード例 #1
0
        /// <summary>
        ///     Sends an object to given client.
        /// </summary>
        /// <param name="client">ID of a client to send the data to</param>
        /// <param name="data">Object to be sent</param>
        public void Send(int client, ISendable data)
        {
            var buffer = new byte[data.ByteLength() + 1];

            buffer[0] = data.Identifier();
            data.GetBytes().CopyTo(buffer, 1);
            _sockets[client].Send(buffer);
        }
コード例 #2
0
        /// <summary>
        ///     Send an object to all clients.
        /// </summary>
        /// <param name="data">Object to be sent</param>
        public void SendAll(ISendable data)
        {
            var buffer = new byte[data.ByteLength() + 1];

            buffer[0] = data.Identifier();
            data.GetBytes().CopyTo(buffer, 1);
            foreach (Socket socket in _sockets)
            {
                socket.Send(buffer);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Sends an object to any clients but given.
        /// </summary>
        /// <param name="client">ID of a client who is not receiving the data.</param>
        /// <param name="data">Object to be sent</param>
        public void SendAllBut(int client, ISendable data)
        {
            var buffer = new byte[data.ByteLength() + 1];

            buffer[0] = data.Identifier();
            data.GetBytes().CopyTo(buffer, 1);
            for (var index = 0; index < _sockets.Count; ++index)
            {
                if (index != client)
                {
                    _sockets[index].Send(buffer);
                }
            }
        }