Class TcpClient
java.lang.Object
it.polimi.ingsw.communication.tcp_client.TcpClient
- Direct Known Subclasses:
SugarClient
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprivate voidHandles all incoming input from the socketprotected voidLogs the message to the current logStreamprotected abstract voidSubclasses override this method to make it behave as they wish.protected abstract voidSubclasses override this method to make it behave as they wish.protected abstract voidSubclasses override this method to make it behave as they wish.private Stringfinal voidrun()protected final voidDelivers message to the serverfinal voidsetLogHeader(String logHeader) final voidsetLogStream(PrintStream logStream)
-
Field Details
-
hostname
-
port
private final int port -
socket
-
logStream
-
logHeader
-
-
Constructor Details
-
TcpClient
-
-
Method Details
-
run
- Throws:
DisconnectionException
-
inputHandler
Handles all incoming input from the socket- Throws:
DisconnectionException
-
readLine
- Throws:
IOException
-
onConnect
protected abstract void onConnect()Subclasses override this method to make it behave as they wish. -
onDisconnect
protected abstract void onDisconnect()Subclasses override this method to make it behave as they wish. -
onMessage
Subclasses override this method to make it behave as they wish.- Parameters:
input- a string received from the socket
-
send
Delivers message to the server- Parameters:
message- message to deliver- Throws:
IOException- if message could not be delivered
-
setLogStream
-
setLogHeader
-
log
Logs the message to the current logStream- Parameters:
message- any log message
-
disconnect
- Throws:
DisconnectionException
-