Package client

Class Packet

java.lang.Object
client.Packet

public class Packet extends Object
The Packet class holds the Packet object which is used commonly within the Client in order to send and recieve data. It can be converted to and from a JadeObject in order to provide ease of use when trying to send structured data.
Since:
2023
  • Constructor Details

    • Packet

      public Packet()
      Null packet constructor
    • Packet

      public Packet(String sender, String reciever, String type, String data)
      Constructor of a packet with no checkSum.checkSum is initialized to 1.
      Parameters:
      sender - this client
      reciever - intended recipient
      type - type of data being sent
      data - the data being sent
    • Packet

      public Packet(String sender, String reciever, String type, String data, String checkSum)
      Constructor of a full packet.
      Parameters:
      sender - this client
      reciever - intended recipient
      type - type of data being sent
      data - the data being sent
      checkSum - check sum of the data
  • Method Details

    • checkPacket

      public boolean checkPacket()
      Returns true if the packet has a valid checkSum for its contents. TODO: implement fully
      Returns:
      boolean
    • toArray

      public String[] toArray()
      Converts the packet into a string array.
      Returns:
      String array
    • toJadeObject

      public JadeObject toJadeObject()
      Converts a Packet object to a JadeObject.This is done by creating a JadePair for each variable of the packet. The JadePairs are then used to create a JadeObject which is then returned. If the data of the packet is null a PacketConversionException is thrown.
      Returns:
      JadeObject
    • toString

      public String toString()
      Converts the packet to a string, this is an unstructured string.
      Overrides:
      toString in class Object
      Returns:
      String
    • getSender

      public String getSender()
      Returns the sender of this.
      Returns:
      String
    • setSender

      public void setSender(String sender)
      Sets the sender of this.
      Parameters:
      sender - sender
    • getReciever

      public String getReciever()
      Returns the reciever of this.
      Returns:
      String
    • setReciever

      public void setReciever(String reciever)
      Sets the reciever of this.
      Parameters:
      reciever - reciever
    • getType

      public String getType()
      Returns the type of this.
      Returns:
      String
    • setType

      public void setType(String type)
      Sets the type of this.
      Parameters:
      type - type
    • getData

      public String getData()
      Returns the data of this.
      Returns:
      String
    • setData

      public void setData(String data)
      Sets the data of this.
      Parameters:
      data - data
    • getCheckSum

      public String getCheckSum()
      Returns the check sum of this.
      Returns:
      String
    • setCheckSum

      public void setCheckSum(String checkSum)
      Sets the check sum of this.
      Parameters:
      checkSum - check sum