public class Frame
extends java.lang.Object
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-------+-+-------------+-------------------------------+ |F|R|R|R| opcode|M| Payload len | Extended payload length | |I|S|S|S| (4) |A| (7) | (16/64) | |N|V|V|V| |S| | (if payload len==126/127) | | |1|2|3| |K| | | +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + | Extended payload length continued, if payload len == 127 | + - - - - - - - - - - - - - - - +-------------------------------+ | |Masking-key, if MASK set to 1 | +-------------------------------+-------------------------------+ | Masking-key (continued) | Payload Data | +-------------------------------- - - - - - - - - - - - - - - - + : Payload Data continued ... : + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | Payload Data continued ... | +---------------------------------------------------------------+
Modifier and Type | Field and Description |
---|---|
static byte |
OPCODE_BINARY |
static byte |
OPCODE_CLOSE |
static byte |
OPCODE_CONTINUE |
static byte |
OPCODE_PING |
static byte |
OPCODE_PONG |
static byte |
OPCODE_TEXT |
Constructor and Description |
---|
Frame()
Constructor: Create a new frame which can be send to a WebSocket client or server.
|
Frame(java.io.PushbackInputStream in)
Constructor: Receive a frame from a WebSocket client or server.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
compileFrame()
Compile a full binary frame which can be send directly to a WebSocket client or server.
|
java.lang.String |
getAsciiDump()
Get a ASCII dump of the frame.
|
long |
getBytesReceived()
Get the total number of bytes of the frame that have received, inclusive the frame overhead (performance data)
|
byte[] |
getExtendedPayloadLength()
Get the extended payload length.
|
byte |
getFinRsvOpcode()
Get the first byte of the frame containing the fin flag and the opcode.
|
java.lang.String |
getHexDump()
Get a HEX dump of the frame.
|
byte[] |
getMaskingKey()
Get the masking key.
|
byte |
getMaskPayload()
Get the second byte of the frame containing the mask flag and the 7-bit payload length
|
byte |
getOpcode()
Get the opcode.
|
byte[] |
getPayload()
Get the payload data.
|
long |
getPayloadLength()
Get the payload length.
|
long |
getReceiveFrameStartNanoTime()
Get the nano time when the first byte of the frame was received (performance data).
|
long |
getReceiveFrameStartTime()
Get the time when the first byte of the frame was received (performance data).
|
boolean |
hasMaskingKey()
Get it the mask flag is set.
|
boolean |
isFin()
Get if the fine flag is set.
|
static java.lang.String |
opcodeToString(byte opcode)
Convert an opcode to a string that can be printed out.
|
void |
setFin(boolean fin)
Set or clear the fin flag.
|
void |
setMaskingKey(byte[] mKey)
Set the masking flag and the masking key, and mask the payload.
|
void |
setOpcode(byte opcode)
Set the opcode.
|
void |
setPayload(byte[] b)
Set the payload.
|
static byte[] |
xorData(byte[] data,
byte[] xorKey)
Perform an XOR operation on a byte array.
|
public static final byte OPCODE_CONTINUE
public static final byte OPCODE_TEXT
public static final byte OPCODE_BINARY
public static final byte OPCODE_CLOSE
public static final byte OPCODE_PING
public static final byte OPCODE_PONG
public Frame()
Frame frame = new Frame(); frame.setFin(true); frame.setOpcode(Frame.OPCODE_TEXT); frame.setPayload("Hello from EchoClient".getBytes("UTF-8")); frame.setMaskingKey(random.get4ByteRandom()); byte[] frameData = frame.compileFrame();
public Frame(java.io.PushbackInputStream in) throws java.io.IOException
in
- the PushbackInputStream of the network connectionjava.io.IOException
- if the network connection is unexpectedly closed, or if an invalid opcode is received, or if an unsupported payload length is receivedpublic void setFin(boolean fin)
fin
- true = set fin flag, false clear fin flagpublic boolean isFin()
public void setOpcode(byte opcode)
opcode
- the opcode to set.OPCODE_CONTINUE
,
OPCODE_TEXT
,
OPCODE_BINARY
,
OPCODE_CLOSE
,
OPCODE_PING
,
OPCODE_PONG
public byte getOpcode()
OPCODE_CONTINUE
,
OPCODE_TEXT
,
OPCODE_BINARY
,
OPCODE_CLOSE
,
OPCODE_PING
,
OPCODE_PONG
public static java.lang.String opcodeToString(byte opcode)
opcode
- the opcodepublic byte getFinRsvOpcode()
public byte getMaskPayload()
public byte[] getExtendedPayloadLength()
public byte[] getPayload()
public void setPayload(byte[] b)
b
- the payloadpublic long getPayloadLength()
public boolean hasMaskingKey()
public byte[] getMaskingKey()
public void setMaskingKey(byte[] mKey)
mKey
- the masking key: 4 bytesjava.lang.IllegalArgumentException
- if the masking key contains less or more than 4 bytessetPayload(byte[])
public static byte[] xorData(byte[] data, byte[] xorKey)
data
- the input data (byte array) on which the XOR operation is appliedxorKey
- the XOR key, a byte[4] arraypublic byte[] compileFrame()
public long getReceiveFrameStartTime()
public long getReceiveFrameStartNanoTime()
public long getBytesReceived()
public java.lang.String getHexDump()
public java.lang.String getAsciiDump()