Package it.polimi.ingsw.Network
Class SocketWrapper
java.lang.Object
it.polimi.ingsw.Network.SocketWrapper
- Direct Known Subclasses:
- KeepAliveSocketWrapper
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final ObjectInputStreamprivate final ObjectOutputStreamprivate final Socket
- 
Constructor SummaryConstructorsConstructorDescriptionSocketWrapper(Socket socket) Create the SocketWrapper around a standard socket
- 
Method SummaryModifier and TypeMethodDescriptionBlocks until a message is readvoidclose()Attempts to close the socket, if the socket is already closed then it does nothingGet the address this socket is bound tobooleanisClosed()Check to see if the socket is closedvoidsendMessage(Message message) Sends a message to the socket endpoint
- 
Field Details- 
sock
- 
input
- 
output
 
- 
- 
Constructor Details- 
SocketWrapperCreate 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- 
awaitMessageBlocks 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 thrown
- IOException
 
- 
closeAttempts 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
 
- 
isClosedpublic boolean isClosed()Check to see if the socket is closed- Returns:
- true if the socket is closed
 
- 
sendMessageSends 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
 
- 
getInetAddressGet the address this socket is bound to- Returns:
- the address this socket is connected to.
 
 
-