private EzyByteBuffer mergeBytes(byte[] bytes)
        {
            int           capacity = buffer.remaining() + bytes.Length;
            EzyByteBuffer merge    = EzyByteBuffer.allocate(capacity);

            merge.put(buffer);
            merge.put(bytes);
            merge.flip();
            return(merge);
        }
        private void writeHeader(EzyByteBuffer buffer, EzyMessageHeader header)
        {
            byte headerByte = 0;

            headerByte |= (byte)(header.isBigSize() ? 1 << 0 : 0);
            headerByte |= (byte)(header.isEncrypted() ? 1 << 1 : 0);
            headerByte |= (byte)(header.isCompressed() ? 1 << 2 : 0);
            headerByte |= (byte)(header.isText() ? 1 << 3 : 0);
            buffer.put(headerByte);
        }
Exemplo n.º 3
0
        protected void sendHandshakeRequest()
        {
            int tokenSize   = sessionToken.Length;
            int messageSize = 0;

            messageSize += 8;         // sessionIdSize
            messageSize += 2;         // tokenLengthSize
            messageSize += tokenSize; // messageSize
            EzyByteBuffer buffer = EzyByteBuffer.allocate(1 + 2 + messageSize);
            byte          header = 0;

            header |= 1 << 5;
            buffer.put(header);
            buffer.putShort((short)messageSize);
            buffer.putLong(sessionId);
            buffer.putShort((short)tokenSize);
            buffer.put(EzyStrings.getBytes(sessionToken));
            buffer.flip();
            byte[] bytes = buffer.getRemainBytes();
            datagramChannel.Send(bytes, bytes.Length);
        }
Exemplo n.º 4
0
        protected override void readSocketData()
        {
            int bytesToRead = socket.GetStream().Read(readBytes, 0, getReadBufferSize());

            if (bytesToRead <= 0)
            {
                return;
            }
            readBuffer.clear();
            readBuffer.put(readBytes, 0, bytesToRead);
            decoder.decode(readBuffer, messageQueue);
            if (messageQueue.Count > 0)
            {
                EzyMessage message    = messageQueue.Dequeue();
                Object     socketData = decoder.decode(message);
                getLogger().debug("receiver data: " + socketData);
                dataEventQueue.add(new EzySocketDataEvent(socketData));
            }
        }
 private void writeContent(EzyByteBuffer buffer, EzyMessage message)
 {
     buffer.put(message.getContent());
 }