Package org.kendar.sync.lib.network
Class TcpConnection
java.lang.Object
org.kendar.sync.lib.network.TcpConnection
- All Implemented Interfaces:
AutoCloseable
Handles TCP communication between the client and server.
-
Constructor Summary
ConstructorsConstructorDescriptionTcpConnection(Socket socket, UUID sessionId, int connectionId, int maxPacketSize) Creates a new TCP connection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the connection.booleanintGets the connection ID.intGets the maximum packet size.Gets the session ID.Gets the socket.inthashCode()booleanisClosed()Receives a message.voidsendMessage(Message message) Sends a message.voidsetConnectionId(int connectionId) voidsetSession(Runnable sessionTouch) Sets the client session associated with this connection.voidsetSessionId(UUID sessionId)
-
Constructor Details
-
TcpConnection
public TcpConnection(Socket socket, UUID sessionId, int connectionId, int maxPacketSize) throws IOException Creates a new TCP connection.- Parameters:
socket- The socketsessionId- The session IDconnectionId- The connection IDmaxPacketSize- The maximum packet size- Throws:
IOException- If an I/O error occurs
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
sendMessage
Sends a message.- Parameters:
message- The message to send- Throws:
IOException- If an I/O error occurs
-
receiveMessage
Receives a message.- Returns:
- The received message
- Throws:
IOException- If an I/O error occurs
-
close
Closes the connection.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- If an I/O error occurs
-
getSessionId
Gets the session ID.- Returns:
- The session ID
-
setSessionId
-
getConnectionId
public int getConnectionId()Gets the connection ID.- Returns:
- The connection ID
-
setConnectionId
public void setConnectionId(int connectionId) -
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
Sets the client session associated with this connection.
-