Package it.polimi.ingsw.Network
Class SocketWrapper
java.lang.Object
it.polimi.ingsw.Network.SocketWrapper
- Direct Known Subclasses:
KeepAliveSocketWrapper
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ObjectInputStream
private final ObjectOutputStream
private final Socket
-
Constructor Summary
ConstructorDescriptionSocketWrapper
(Socket socket) Create the SocketWrapper around a standard socket -
Method Summary
Modifier and TypeMethodDescriptionBlocks until a message is readvoid
close()
Attempts to close the socket, if the socket is already closed then it does nothingGet the address this socket is bound toboolean
isClosed()
Check to see if the socket is closedvoid
sendMessage
(Message message) Sends a message to the socket endpoint
-
Field Details
-
sock
-
input
-
output
-
-
Constructor Details
-
SocketWrapper
Create the SocketWrapper around a standard socket- Parameters:
socket
- the socket to wrap around- Throws:
IOException
- if the socket/wrapper has issues opening its streams
-
-
Method Details
-
awaitMessage
Blocks until a message is read- Returns:
- the read
Message
- Throws:
SocketException
- if there's an error while reading from the object stream, the socket will close and this exception is thrownIOException
-
close
Attempts to close the socket, if the socket is already closed then it does nothing- Throws:
IOException
- if any exception happens during closing of the socket
-
isClosed
public boolean isClosed()Check to see if the socket is closed- Returns:
- true if the socket is closed
-
sendMessage
Sends a message to the socket endpoint- Parameters:
message
- the message to send, required not null- Throws:
IOException
- if any error happens during the sending of the message
-
getInetAddress
Get the address this socket is bound to- Returns:
- the address this socket is connected to.
-