Class Draft_6455
java.lang.Object
org.java_websocket.drafts.Draft
org.java_websocket.drafts.Draft_6455
Implementation for the RFC 6455 websocket protocol This is the recommended class for your
websocket connection
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<ByteBuffer> Attribute for the payload of the current continuous frameprivate static final StringHandshake specific field for the connectionprivate FramedataAttribute for the current continuous frameprivate IExtensionCurrent active extension used to decode messagesprivate IExtensionAttribute for the default extensionprivate ByteBufferAttribute for the current incomplete frameprivate List<IExtension> Attribute for all available extension in this draftAttribute for all available protocols in this draftprivate final org.slf4j.LoggerLogger instanceprivate intAttribute for the maximum allowed size of a frameprivate IExtensionAttribute for the used extension in this draftprivate IProtocolAttribute for the used protocol in this draftprivate final SecureRandomAttribute for the reusable random instanceprivate static final StringHandshake specific field for the acceptprivate static final StringHandshake specific field for the extensionprivate static final StringHandshake specific field for the keyprivate static final StringHandshake specific field for the protocolprivate static final StringHandshake specific field for the upgradeFields inherited from class Draft
continuousFrameType, role -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for the websocket protocol specified by RFC 6455 with default extensionsDraft_6455(List<IExtension> inputExtensions) Constructor for the websocket protocol specified by RFC 6455 with custom extensionsDraft_6455(List<IExtension> inputExtensions, int inputMaxFrameSize) Constructor for the websocket protocol specified by RFC 6455 with custom extensions and protocolsDraft_6455(List<IExtension> inputExtensions, List<IProtocol> inputProtocols) Constructor for the websocket protocol specified by RFC 6455 with custom extensions and protocolsDraft_6455(List<IExtension> inputExtensions, List<IProtocol> inputProtocols, int inputMaxFrameSize) Constructor for the websocket protocol specified by RFC 6455 with custom extensions and protocolsDraft_6455(IExtension inputExtension) Constructor for the websocket protocol specified by RFC 6455 with custom extensions -
Method Summary
Modifier and TypeMethodDescriptionacceptHandshakeAsClient(ClientHandshake request, ServerHandshake response) acceptHandshakeAsServer(ClientHandshake handshakedata) private voidaddToBufferList(ByteBuffer payloadData) Add a payload to the current bytebuffer listprivate voidCheck the current size of the buffer and throw an exception if the size is bigger than the max allowed frame sizeprivate voidClear the current bytebuffer listprivate HandshakeStatecontainsRequestedProtocol(String requestedProtocol) Check if the requested protocol is part of this draftDrafts must only be by one websocket at all.createBinaryFrame(Framedata framedata) private ByteBuffercreateByteBufferFromFramedata(Framedata framedata) createFrames(String text, boolean mask) createFrames(ByteBuffer binary, boolean mask) booleanprivate bytefromOpcode(Opcode opcode) private StringGenerate a final key from a input stringprivate longGet the current size of the resulting bytebuffer in the bytebuffer listGetter for the extension which is used by this draftGetter for all available extensions for this draftGetter for all available protocols for this draftprivate bytegetMaskByte(boolean mask) Get the mask byte if existingintGetter for the maximum allowed payload size which is used by this draftprivate ByteBufferMethod to generate a full bytebuffer out of all the fragmented frame payloadGetter for the protocol which is used by this draftprivate bytegetRSVByte(int rsv) Get a byte that can set RSV bits when OR(|)'d.private StringGenerate a date for for the date-headerprivate intgetSizeBytes(ByteBuffer mes) Get the size bytes for the byte bufferinthashCode()private voidlogRuntimeException(WebSocketImpl webSocketImpl, RuntimeException e) Log the runtime exception to the specific WebSocketImplpostProcessHandshakeResponseAsServer(ClientHandshake request, ServerHandshakeBuilder response) voidprocessFrame(WebSocketImpl webSocketImpl, Framedata frame) Handle the frame specific to the draftprivate voidprocessFrameBinary(WebSocketImpl webSocketImpl, Framedata frame) Process the frame if it is a binary frameprivate voidprocessFrameClosing(WebSocketImpl webSocketImpl, Framedata frame) Process the frame if it is a closing frameprivate voidprocessFrameContinuousAndNonFin(WebSocketImpl webSocketImpl, Framedata frame, Opcode curop) Process the frame if it is a continuous frame or the fin bit is not setprivate voidprocessFrameIsFin(WebSocketImpl webSocketImpl, Framedata frame) Process the frame if it is the last frameprivate voidprocessFrameIsNotFin(Framedata frame) Process the frame if it is not the last frameprivate voidprocessFrameText(WebSocketImpl webSocketImpl, Framedata frame) Process the frame if it is a text framevoidreset()private byte[]toByteArray(long val, int bytecount) private OpcodetoOpcode(byte opcode) toString()translateFrame(ByteBuffer buffer) private FramedatatranslateSingleFrame(ByteBuffer buffer) private voidtranslateSingleFrameCheckLengthLimit(long length) Check if the frame size exceeds the allowed limitprivate voidtranslateSingleFrameCheckPacketSize(int maxpacketsize, int realpacketsize) Check if the max packet size is smaller than the real packet sizetranslateSingleFramePayloadLength(ByteBuffer buffer, Opcode optcode, int oldPayloadlength, int maxpacketsize, int oldRealpacketsize) Translate the buffer depending when it has an extended payload length (126 or 127)Methods inherited from class Draft
basicAccept, checkAlloc, continuousFrame, createHandshake, createHandshake, createHandshake, createHandshake, getRole, readLine, readStringLine, readVersion, setParseMode, translateHandshake, translateHandshakeHttp
-
Field Details
-
SEC_WEB_SOCKET_KEY
-
SEC_WEB_SOCKET_PROTOCOL
Handshake specific field for the protocol- See Also:
-
SEC_WEB_SOCKET_EXTENSIONS
Handshake specific field for the extension- See Also:
-
SEC_WEB_SOCKET_ACCEPT
-
UPGRADE
-
CONNECTION
-
log
private final org.slf4j.Logger logLogger instance- Since:
- 1.4.0
-
negotiatedExtension
Attribute for the used extension in this draft -
defaultExtension
Attribute for the default extension -
knownExtensions
Attribute for all available extension in this draft -
currentDecodingExtension
Current active extension used to decode messages -
protocol
Attribute for the used protocol in this draft -
knownProtocols
-
currentContinuousFrame
Attribute for the current continuous frame -
byteBufferList
Attribute for the payload of the current continuous frame -
incompleteframe
Attribute for the current incomplete frame -
reuseableRandom
Attribute for the reusable random instance -
maxFrameSize
private int maxFrameSizeAttribute for the maximum allowed size of a frame- Since:
- 1.4.0
-
-
Constructor Details
-
Draft_6455
public Draft_6455()Constructor for the websocket protocol specified by RFC 6455 with default extensions- Since:
- 1.3.5
-
Draft_6455
Constructor for the websocket protocol specified by RFC 6455 with custom extensions- Parameters:
inputExtension- the extension which should be used for this draft- Since:
- 1.3.5
-
Draft_6455
Constructor for the websocket protocol specified by RFC 6455 with custom extensions- Parameters:
inputExtensions- the extensions which should be used for this draft- Since:
- 1.3.5
-
Draft_6455
Constructor for the websocket protocol specified by RFC 6455 with custom extensions and protocols- Parameters:
inputExtensions- the extensions which should be used for this draftinputProtocols- the protocols which should be used for this draft- Since:
- 1.3.7
-
Draft_6455
Constructor for the websocket protocol specified by RFC 6455 with custom extensions and protocols- Parameters:
inputExtensions- the extensions which should be used for this draftinputMaxFrameSize- the maximum allowed size of a frame (the real payload size, decoded frames can be bigger)- Since:
- 1.4.0
-
Draft_6455
public Draft_6455(List<IExtension> inputExtensions, List<IProtocol> inputProtocols, int inputMaxFrameSize) Constructor for the websocket protocol specified by RFC 6455 with custom extensions and protocols- Parameters:
inputExtensions- the extensions which should be used for this draftinputProtocols- the protocols which should be used for this draftinputMaxFrameSize- the maximum allowed size of a frame (the real payload size, decoded frames can be bigger)- Since:
- 1.4.0
-
-
Method Details
-
acceptHandshakeAsServer
public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata) throws InvalidHandshakeException - Specified by:
acceptHandshakeAsServerin classDraft- Throws:
InvalidHandshakeException
-
containsRequestedProtocol
Check if the requested protocol is part of this draft- Parameters:
requestedProtocol- the requested protocol- Returns:
- MATCHED if it is matched, otherwise NOT_MATCHED
-
acceptHandshakeAsClient
public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHandshake response) throws InvalidHandshakeException - Specified by:
acceptHandshakeAsClientin classDraft- Throws:
InvalidHandshakeException
-
getExtension
Getter for the extension which is used by this draft- Returns:
- the extension which is used or null, if handshake is not yet done
-
getKnownExtensions
Getter for all available extensions for this draft- Returns:
- the extensions which are enabled for this draft
-
getProtocol
Getter for the protocol which is used by this draft- Returns:
- the protocol which is used or null, if handshake is not yet done or no valid protocols
- Since:
- 1.3.7
-
getMaxFrameSize
public int getMaxFrameSize()Getter for the maximum allowed payload size which is used by this draft- Returns:
- the size, which is allowed for the payload
- Since:
- 1.4.0
-
getKnownProtocols
-
postProcessHandshakeRequestAsClient
- Specified by:
postProcessHandshakeRequestAsClientin classDraft
-
postProcessHandshakeResponseAsServer
public HandshakeBuilder postProcessHandshakeResponseAsServer(ClientHandshake request, ServerHandshakeBuilder response) throws InvalidHandshakeException - Specified by:
postProcessHandshakeResponseAsServerin classDraft- Throws:
InvalidHandshakeException
-
copyInstance
Description copied from class:DraftDrafts must only be by one websocket at all. To prevent drafts to be used more than once the Websocket implementation should call this method in order to create a new usable version of a given draft instance.
The copy can be safely used in conjunction with a new websocket connection.- Specified by:
copyInstancein classDraft- Returns:
- a copy of the draft
-
createBinaryFrame
- Specified by:
createBinaryFramein classDraft
-
createByteBufferFromFramedata
-
translateSingleFrame
private Framedata translateSingleFrame(ByteBuffer buffer) throws IncompleteException, InvalidDataException -
translateSingleFramePayloadLength
private Draft_6455.TranslatedPayloadMetaData translateSingleFramePayloadLength(ByteBuffer buffer, Opcode optcode, int oldPayloadlength, int maxpacketsize, int oldRealpacketsize) throws InvalidFrameException, IncompleteException, LimitExceededException Translate the buffer depending when it has an extended payload length (126 or 127)- Parameters:
buffer- the buffer to read fromoptcode- the decoded optcodeoldPayloadlength- the old payload lengthmaxpacketsize- the max packet size allowedoldRealpacketsize- the real packet size- Returns:
- the new payload data containing new payload length and new packet size
- Throws:
InvalidFrameException- thrown if a control frame has an invalid lengthIncompleteException- if the maxpacketsize is smaller than the realpackagesizeLimitExceededException- if the payload length is to big
-
translateSingleFrameCheckLengthLimit
Check if the frame size exceeds the allowed limit- Parameters:
length- the current payload length- Throws:
LimitExceededException- if the payload length is to big
-
translateSingleFrameCheckPacketSize
private void translateSingleFrameCheckPacketSize(int maxpacketsize, int realpacketsize) throws IncompleteException Check if the max packet size is smaller than the real packet size- Parameters:
maxpacketsize- the max packet sizerealpacketsize- the real packet size- Throws:
IncompleteException- if the maxpacketsize is smaller than the realpackagesize
-
getRSVByte
private byte getRSVByte(int rsv) Get a byte that can set RSV bits when OR(|)'d. 0 1 2 3 4 5 6 7 +-+-+-+-+-------+ |F|R|R|R| opcode| |I|S|S|S| (4) | |N|V|V|V| | | |1|2|3| |- Parameters:
rsv- Can only be {0, 1, 2, 3}- Returns:
- byte that represents which RSV bit is set.
-
getMaskByte
private byte getMaskByte(boolean mask) Get the mask byte if existing- Parameters:
mask- is mask active or not- Returns:
- -128 for true, 0 for false
-
getSizeBytes
Get the size bytes for the byte buffer- Parameters:
mes- the current buffer- Returns:
- the size bytes
-
translateFrame
- Specified by:
translateFramein classDraft- Throws:
InvalidDataException
-
createFrames
- Specified by:
createFramesin classDraft
-
createFrames
- Specified by:
createFramesin classDraft
-
reset
-
getServerTime
-
generateFinalKey
-
toByteArray
private byte[] toByteArray(long val, int bytecount) -
fromOpcode
-
toOpcode
- Throws:
InvalidFrameException
-
processFrame
Description copied from class:DraftHandle the frame specific to the draft- Specified by:
processFramein classDraft- Parameters:
webSocketImpl- the websocketimpl used for this draftframe- the frame which is supposed to be handled- Throws:
InvalidDataException- will be thrown on invalid data
-
processFrameContinuousAndNonFin
private void processFrameContinuousAndNonFin(WebSocketImpl webSocketImpl, Framedata frame, Opcode curop) throws InvalidDataException Process the frame if it is a continuous frame or the fin bit is not set- Parameters:
webSocketImpl- the websocket implementation to useframe- the current framecurop- the current Opcode- Throws:
InvalidDataException- if there is a protocol error
-
processFrameBinary
Process the frame if it is a binary frame- Parameters:
webSocketImpl- the websocket implframe- the frame
-
logRuntimeException
Log the runtime exception to the specific WebSocketImpl- Parameters:
webSocketImpl- the implementation of the websockete- the runtime exception
-
processFrameText
private void processFrameText(WebSocketImpl webSocketImpl, Framedata frame) throws InvalidDataException Process the frame if it is a text frame- Parameters:
webSocketImpl- the websocket implframe- the frame- Throws:
InvalidDataException
-
processFrameIsFin
private void processFrameIsFin(WebSocketImpl webSocketImpl, Framedata frame) throws InvalidDataException Process the frame if it is the last frame- Parameters:
webSocketImpl- the websocket implframe- the frame- Throws:
InvalidDataException- if there is a protocol error
-
processFrameIsNotFin
Process the frame if it is not the last frame- Parameters:
frame- the frame- Throws:
InvalidDataException- if there is a protocol error
-
processFrameClosing
Process the frame if it is a closing frame- Parameters:
webSocketImpl- the websocket implframe- the frame
-
clearBufferList
private void clearBufferList()Clear the current bytebuffer list -
addToBufferList
Add a payload to the current bytebuffer list- Parameters:
payloadData- the new payload
-
checkBufferLimit
Check the current size of the buffer and throw an exception if the size is bigger than the max allowed frame size- Throws:
LimitExceededException- if the current size is bigger than the allowed size
-
getCloseHandshakeType
- Specified by:
getCloseHandshakeTypein classDraft
-
toString
-
equals
-
hashCode
-
getPayloadFromByteBufferList
Method to generate a full bytebuffer out of all the fragmented frame payload- Returns:
- a bytebuffer containing all the data
- Throws:
LimitExceededException- will be thrown when the totalSize is bigger then Integer.MAX_VALUE due to not being able to allocate more
-
getByteBufferListSize
private long getByteBufferListSize()Get the current size of the resulting bytebuffer in the bytebuffer list- Returns:
- the size as long (to not get an integer overflow)
-