java.lang.Object
com.renomad.minum.web.SocketWrapper
- All Implemented Interfaces:
ISocketWrapper,Closeable,AutoCloseable
This wraps Sockets to make them more particular to our use case
-
Constructor Summary
ConstructorsConstructorDescriptionSocketWrapper(Socket socket, IServer server, ILogger logger, int timeoutMillis, String hostName) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()Send the data in the outgoing buffer into the socket.The hostname of the server, as set in the configuration file of key HOST_NAME inConstants.hostNameReturns this socket's input stream for more granular accessintGet the port of the serverReturns a string of the remote host address without portReturns aSocketAddress, which includes the client's address and portvoidsend(byte[] bodyContents) Simply send the bytes on the socket, simple as that.voidsend(byte[] bodyContents, int off, int len) voidsend(int b) voidConvert the provided string value into bytes using the default charset, and send on the socket.voidsendHttpLine(String msg) Sends a line of text, with carriage-return and line-feed appended to the end, required for the HTTP protocol.toString()Note that since we are indicating just the remote address as the unique value, in cases like tests where we are operating as sometimes server or client, you might see the server as the remote.
-
Constructor Details
-
SocketWrapper
public SocketWrapper(Socket socket, IServer server, ILogger logger, int timeoutMillis, String hostName) throws IOException Constructor- Parameters:
socket- a socket we intend to wrap with methods applicable to our use caseslogger- not much more to say on this paramtimeoutMillis- we'll configure the socket to timeout after this many milliseconds.- Throws:
IOException
-
-
Method Details
-
send
Description copied from interface:ISocketWrapperConvert the provided string value into bytes using the default charset, and send on the socket.- Specified by:
sendin interfaceISocketWrapper- Throws:
IOException
-
send
Description copied from interface:ISocketWrapperSimply send the bytes on the socket, simple as that.- Specified by:
sendin interfaceISocketWrapper- Throws:
IOException
-
send
- Specified by:
sendin interfaceISocketWrapper- Throws:
IOException
-
send
- Specified by:
sendin interfaceISocketWrapper- Throws:
IOException
-
sendHttpLine
Description copied from interface:ISocketWrapperSends a line of text, with carriage-return and line-feed appended to the end, required for the HTTP protocol.- Specified by:
sendHttpLinein interfaceISocketWrapper- Throws:
IOException
-
getLocalPort
public int getLocalPort()Description copied from interface:ISocketWrapperGet the port of the server- Specified by:
getLocalPortin interfaceISocketWrapper
-
getRemoteAddrWithPort
Description copied from interface:ISocketWrapperReturns aSocketAddress, which includes the client's address and port- Specified by:
getRemoteAddrWithPortin interfaceISocketWrapper
-
getRemoteAddr
Description copied from interface:ISocketWrapperReturns a string of the remote host address without port- Specified by:
getRemoteAddrin interfaceISocketWrapper
-
getServerType
- Specified by:
getServerTypein interfaceISocketWrapper
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceISocketWrapper- Throws:
IOException
-
getInputStream
Description copied from interface:ISocketWrapperReturns this socket's input stream for more granular access- Specified by:
getInputStreamin interfaceISocketWrapper
-
toString
Note that since we are indicating just the remote address as the unique value, in cases like tests where we are operating as sometimes server or client, you might see the server as the remote. -
getHostName
Description copied from interface:ISocketWrapperThe hostname of the server, as set in the configuration file of key HOST_NAME inConstants.hostName- Specified by:
getHostNamein interfaceISocketWrapper
-
flush
Description copied from interface:ISocketWrapperSend the data in the outgoing buffer into the socket.- Specified by:
flushin interfaceISocketWrapper- Throws:
IOException
-