Example #1
0
        void SendImpl(PeerEntry peer, byte[] buf, int offset, int size, bool encrypt)
        {
            Log.Trace("Send id:{0}, size:{1}, encrypt:{2}", peer.ConnectionId, size, encrypt);
            int packetSize;
            int id = GetSendId(peer.ConnectionId);

            if (encrypt)
            {
                var msg = new EncryptMessage(id, peer, new ArraySegment <byte>(buf, offset, size));
                packetSize = msg.Pack(m_SendBuffer, peer.Encryptor);
            }
            else
            {
                var msg = new PlainMessage(id, peer, new ArraySegment <byte>(buf, offset, size));
                packetSize = msg.Pack(m_SendBuffer);
            }
            m_Socket.Send(m_SendBuffer, 0, packetSize, peer.EndPoint);
        }