Package client
Class SingleClient
java.lang.Object
client.SingleClient
The SingleClient acts as a singleton that interacts with a single instance of a Client object.
This is useful for the behaviors as it means clients do not to be closed and opened for each behavior.
- Since:
- 2023
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns whether or not the client is currently connected.static SingleClient
Returns the instance of this client and initialises it if it is null.static Packet
Returns the latest packet from the server.static Packet
Gets a packet from the server.static void
static void
sendDataPacket
(String data) Sends a piece of data that is passed as a string.A packet is constructed from the string and then sent via the client.static void
sendPacket
(Packet packet) Sends a packet via the clients sendPacket() method.static void
sendStatePacket
(States state) Sends a state via a packet which is constructed and sent via the client.static void
setLatestPacket
(Packet packet) Sets the value of the latest packet from the server.
-
Method Details
-
initialize
public static void initialize() -
getInstance
Returns the instance of this client and initialises it if it is null.- Returns:
- SingleClient
-
clientConnected
public static boolean clientConnected()Returns whether or not the client is currently connected.- Returns:
- boolean
-
sendPacket
Sends a packet via the clients sendPacket() method.- Parameters:
packet
-
-
sendDataPacket
Sends a piece of data that is passed as a string.A packet is constructed from the string and then sent via the client.- Parameters:
data
-
-
sendStatePacket
Sends a state via a packet which is constructed and sent via the client.- Parameters:
state
- current state of robot
-
getLatestPacket
Returns the latest packet from the server.- Returns:
- Packet
-
setLatestPacket
Sets the value of the latest packet from the server.- Parameters:
packet
-
-
getPacket
Gets a packet from the server.- Returns:
- Packet
-