public enum PacketType extends Enum<PacketType>
| Enum Constant and Description |
|---|
ACK
(6) ACK
|
CONNECT
(1) Connect
|
DISCONNECT
(0) Disconnect
|
ERROR
(7) Error
|
EVENT
(5) Event
|
HEARTBEAT
(2) Heartbeat
|
JSON
(4) JSON Message
|
MESSAGE
(3) Message
|
NOOP
(8) Noop
|
| Modifier and Type | Method and Description |
|---|---|
int |
getValue() |
byte[] |
getValueAsBytes() |
static PacketType |
valueOf(int value) |
static PacketType |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static PacketType[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final PacketType DISCONNECT
Signals disconnection. If no endpoint is specified, disconnects the entire socket.
Examples:
Disconnect a socket connected to the /test endpoint:
0::/test
Disconnect the whole socket:
0
public static final PacketType CONNECT
Only used for multiple sockets. Signals a connection to the endpoint. Once the server receives it, it's echoed back to the client.
Example, if the client is trying to connect to the endpoint /test, a message like this will be delivered:
'1::' [path] [query]
Example:
1::/test?my=param
To acknowledge the connection, the server echoes back the message. Otherwise, the server might want to respond with a error packet.
public static final PacketType HEARTBEAT
Sends a heartbeat. Heartbeats must be sent within the interval negotiated with the server. It's up to the client to decide the padding (for example, if the heartbeat timeout negotiated with the server is 20s, the client might want to send a heartbeat evert 15s).
public static final PacketType MESSAGE
'3:' [message id ('+')] ':' [message endpoint] ':' [data]
A regular message.
3:1::blabla
public static final PacketType JSON
'4:' [message id ('+')] ':' [message endpoint] ':' [json]
A JSON encoded message.
4:1:: "a":"b"
public static final PacketType EVENT
'5:' [message id ('+')] ':' [message endpoint] ':' [json encoded event]
An event is like a json message, but has mandatory name and args fields. name is a string and args an array.
The event names:
'message''connect''disconnect''open''close''error''retry''reconnect'are reserved, and cannot be used by clients or servers with this message type.
public static final PacketType ACK
'6:::' [message id] '+' [data]
An acknowledgment contains the message id as the message data. If a + sign follows the message id, it's treated as an event message packet.
Example 1: simple acknowledgement
6:::4
Example 2: complex acknowledgement
6:::4+["A","B"]
public static final PacketType ERROR
'7::' [endpoint] ':' [reason] '+' [advice]
For example, if a connection to a sub-socket is unauthorized.
public static final PacketType NOOP
No operation. Used for example to close a poll after the polling duration times out.
public static PacketType[] values()
for (PacketType c : PacketType.values()) System.out.println(c);
public static PacketType valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic int getValue()
public byte[] getValueAsBytes()
public static PacketType valueOf(int value)
Copyright © 2012–2016. All rights reserved.