示例#1
0
        /// <summary>
        /// Sends the specified payload over UDP.
        /// </summary>
        /// <param name="payloadWriter">The action which writes the payload to a buffer.</param>
        public void SendUdp(Action <BitBuffer> payloadWriter)
        {
            lock (this) {
                if (CurrentState == State.Disconnected)
                {
                    return;
                }

                using (_sendBuffer) {
                    UdpHelper.WritePrefix(_sendBuffer, ConnectionStartTimestamp, payloadWriter);
                    byte[] encrypted = _crypto.Encrypt(_sendBuffer.Array, 0, _sendBuffer.Size);
                    _udp.Send(encrypted, 0, encrypted.Length);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Sends the specified payload over UDP to the specified client.
        /// </summary>
        /// <param name="recipient">The client in question.</param>
        /// <param name="payloadWriter">The action which writes the payload to a buffer.</param>
        public void SendUdp(IDoubleServerClient recipient, Action <BitBuffer> payloadWriter)
        {
            lock (this) {
                if (_closed)
                {
                    return;
                }

                DoubleServerClient client = (DoubleServerClient)recipient;
                using (_sendBuffer) {
                    UdpHelper.WritePrefix(_sendBuffer, client.ConnectionStartTimestamp, payloadWriter);
                    byte[] encrypted = _crypto.Encrypt(client.EncryptionKey, _sendBuffer.Array, 0, _sendBuffer.Size);
                    _udp.Send(client.UdpEndPoint, encrypted, 0, encrypted.Length);
                }
            }
        }