Top Description Fields Constructors Methods
org.java_websocket.framing

public Class CloseFrame

extends ControlFrame
Class Inheritance
Imports
java.nio.ByteBuffer, org.java_websocket.enums.Opcode, org.java_websocket.exceptions.InvalidDataException, .InvalidFrameException, org.java_websocket.util.ByteBufferUtils, .Charsetfunctions

Class to represent a close frame

Field Summary

Modifier and TypeField and Description
public static final int
ABNORMAL_CLOSE

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final int
BAD_GATEWAY

1014 indicates that the server was acting as a gateway or proxy and received an invalid response from the upstream server.

public static final int
BUGGYCLOSE

The connection had a buggy close (this should not happen)

private int
code

The close code used in this close frame

public static final int
EXTENSION

1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake.

public static final int
FLASHPOLICY

The connection was flushed and closed

public static final int
GOING_AWAY

1001 indicates that an endpoint is "going away", such as a server going down, or a browser having navigated away from a page.

public static final int
NEVER_CONNECTED

The connection had never been established

public static final int
NO_UTF8

1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message).

public static final int
NOCODE

1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final int
NORMAL

indicates a normal closure, meaning whatever purpose the connection was established for has been fulfilled.

public static final int
POLICY_VALIDATION

1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy.

public static final int
PROTOCOL_ERROR

1002 indicates that an endpoint is terminating the connection due to a protocol error.

private String
reason

The close message used in this close frame

public static final int
REFUSE

1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g. an endpoint that understands only text data MAY send this if it receives a binary message).

public static final int
SERVICE_RESTART

1012 indicates that the service is restarted.

public static final int
TLS_ERROR

1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final int
TOOBIG

1009 indicates that an endpoint is terminating the connection because it has received a message which is too big for it to process.

public static final int
TRY_AGAIN_LATER

1013 indicates that the service is experiencing overload.

public static final int
UNEXPECTED_CONDITION

1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

Constructor Summary

AccessConstructor and Description
public
CloseFrame()

Constructor for a close frame

Using opcode closing and fin = true

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides org.java_websocket.framing.FramedataImpl1.equals.

Indicates whether some other object is "equal to" this one.

public int

Returns:

the used close code
getCloseCode
()

Get the used close code

public String

Returns:

the message in this frame
getMessage
()

Get the message that closeframe is containing

public ByteBuffer
public int
hashCode()

Overrides org.java_websocket.framing.FramedataImpl1.hashCode.

Returns a hash code value for this object.

public void
isValid()

Overrides org.java_websocket.framing.ControlFrame.isValid.

Check if the frame is valid due to specification

public void
setCode(int
the close code
code
)

Set the close code for this close frame

public void
setPayload(ByteBuffer payload)

Overrides org.java_websocket.framing.FramedataImpl1.setPayload.

Set the payload of this frame to the provided payload

public void
setReason(String
the reason code
reason
)

Set the close reason for this close frame

public String
toString()

Overrides org.java_websocket.framing.FramedataImpl1.toString.

Returns a string representation of the object.

private void
updatePayload()

Update the payload to represent the close code and the reason

private void
validateUtf8(ByteBuffer
the current payload
payload
,
int
the current mark
mark
)

Validate the payload to valid utf8

Field Detail

ABNORMAL_CLOSEback to summary
public static final int ABNORMAL_CLOSE

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g. without sending or receiving a Close control frame.

BAD_GATEWAYback to summary
public static final int BAD_GATEWAY

1014 indicates that the server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code See https://www.ietf.org/mail-archive/web/hybi/current/msg10748.html fore more information.

Since
1.3.8
BUGGYCLOSEback to summary
public static final int BUGGYCLOSE

The connection had a buggy close (this should not happen)

codeback to summary
private int code

The close code used in this close frame

EXTENSIONback to summary
public static final int EXTENSION

1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. The list of extensions which are needed SHOULD appear in the /reason/ part of the Close frame. Note that this status code is not used by the server, because it can fail the WebSocket handshake instead.

FLASHPOLICYback to summary
public static final int FLASHPOLICY

The connection was flushed and closed

GOING_AWAYback to summary
public static final int GOING_AWAY

1001 indicates that an endpoint is "going away", such as a server going down, or a browser having navigated away from a page.

NEVER_CONNECTEDback to summary
public static final int NEVER_CONNECTED

The connection had never been established

NO_UTF8back to summary
public static final int NO_UTF8

1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message).

NOCODEback to summary
public static final int NOCODE

1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that no status code was actually present.

NORMALback to summary
public static final int NORMAL

indicates a normal closure, meaning whatever purpose the connection was established for has been fulfilled.

POLICY_VALIDATIONback to summary
public static final int POLICY_VALIDATION

1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy. This is a generic status code that can be returned when there is no other more suitable status code (e.g. 1003 or 1009), or if there is a need to hide specific details about the policy.

PROTOCOL_ERRORback to summary
public static final int PROTOCOL_ERROR

1002 indicates that an endpoint is terminating the connection due to a protocol error.

reasonback to summary
private String reason

The close message used in this close frame

REFUSEback to summary
public static final int REFUSE

1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g. an endpoint that understands only text data MAY send this if it receives a binary message).

SERVICE_RESTARTback to summary
public static final int SERVICE_RESTART

1012 indicates that the service is restarted. A client may reconnect, and if it choses to do, should reconnect using a randomized delay of 5 - 30s. See https://www.ietf.org/mail-archive/web/hybi/current/msg09670.html for more information.

Since
1.3.8
TLS_ERRORback to summary
public static final int TLS_ERROR

1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).

TOOBIGback to summary
public static final int TOOBIG

1009 indicates that an endpoint is terminating the connection because it has received a message which is too big for it to process.

TRY_AGAIN_LATERback to summary
public static final int TRY_AGAIN_LATER

1013 indicates that the service is experiencing overload. A client should only connect to a different IP (when there are multiple for the target) or reconnect to the same IP upon user action. See https://www.ietf.org/mail-archive/web/hybi/current/msg09670.html for more information.

Since
1.3.8
UNEXPECTED_CONDITIONback to summary
public static final int UNEXPECTED_CONDITION

1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

Constructor Detail

CloseFrameback to summary
public CloseFrame()

Constructor for a close frame

Using opcode closing and fin = true

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides org.java_websocket.framing.FramedataImpl1.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getCloseCodeback to summary
public int getCloseCode()

Get the used close code

Returns:int

the used close code

getMessageback to summary
public String getMessage()

Get the message that closeframe is containing

Returns:String

the message in this frame

getPayloadDataback to summary
public ByteBuffer getPayloadData()

Overrides org.java_websocket.framing.FramedataImpl1.getPayloadData.

Implements org.java_websocket.framing.Framedata.getPayloadData.

Doc from org.java_websocket.framing.Framedata.getPayloadData.

The "Payload data" which was sent in this frame

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides org.java_websocket.framing.FramedataImpl1.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isValidback to summary
public void isValid() throws InvalidDataException

Overrides org.java_websocket.framing.ControlFrame.isValid.

Doc from org.java_websocket.framing.FramedataImpl1.isValid.

Check if the frame is valid due to specification

Annotations
@Override
Exceptions
InvalidDataException:
thrown if the frame is not a valid frame
setCodeback to summary
public void setCode(int code)

Set the close code for this close frame

Parameters
code:int

the close code

setPayloadback to summary
public void setPayload(ByteBuffer payload)

Overrides org.java_websocket.framing.FramedataImpl1.setPayload.

Doc from org.java_websocket.framing.FramedataImpl1.setPayload.

Set the payload of this frame to the provided payload

Annotations
@Override
setReasonback to summary
public void setReason(String reason)

Set the close reason for this close frame

Parameters
reason:String

the reason code

toStringback to summary
public String toString()

Overrides org.java_websocket.framing.FramedataImpl1.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
updatePayloadback to summary
private void updatePayload()

Update the payload to represent the close code and the reason

validateUtf8back to summary
private void validateUtf8(ByteBuffer payload, int mark) throws InvalidDataException

Validate the payload to valid utf8

Parameters
payload:ByteBuffer

the current payload

mark:int

the current mark

Exceptions
InvalidDataException:
the current payload is not a valid utf8