Class TcpConnection

java.lang.Object
org.kendar.sync.lib.network.TcpConnection
All Implemented Interfaces:
AutoCloseable

public class TcpConnection extends Object implements AutoCloseable
Handles TCP communication between the client and server.
  • Constructor Details

    • TcpConnection

      public TcpConnection(Socket socket, UUID sessionId, int connectionId, int maxPacketSize) throws IOException
      Creates a new TCP connection.
      Parameters:
      socket - The socket
      sessionId - The session ID
      connectionId - The connection ID
      maxPacketSize - The maximum packet size
      Throws:
      IOException - If an I/O error occurs
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • sendMessage

      public void sendMessage(Message message) throws IOException
      Sends a message.
      Parameters:
      message - The message to send
      Throws:
      IOException - If an I/O error occurs
    • receiveMessage

      public Message receiveMessage() throws IOException
      Receives a message.
      Returns:
      The received message
      Throws:
      IOException - If an I/O error occurs
    • close

      public void close() throws IOException
      Closes the connection.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - If an I/O error occurs
    • getSessionId

      public UUID getSessionId()
      Gets the session ID.
      Returns:
      The session ID
    • setSessionId

      public void setSessionId(UUID sessionId)
    • getConnectionId

      public int getConnectionId()
      Gets the connection ID.
      Returns:
      The connection ID
    • setConnectionId

      public void setConnectionId(int connectionId)
    • getSocket

      public Socket getSocket()
      Gets the socket.
      Returns:
      The socket
    • getMaxPacketSize

      public int getMaxPacketSize()
      Gets the maximum packet size.
      Returns:
      The maximum packet size
    • isClosed

      public boolean isClosed()
    • setSession

      public void setSession(Runnable sessionTouch)
      Sets the client session associated with this connection.