Package gda.io.socket
Class NativeSock
java.lang.Object
gda.io.socket.NativeSock
- Direct Known Subclasses:
ODCCDNativeSock
Title: Socket wrapper with little to big endian conversion read methods.
Description: This class is a general purpose socket wrapper. It is particulary useful for reading from little
endian byte streams (native Intel format). Some methods are provided to read java big endian data types from the
little endian byte stream. Some methods are also provided to just read bytes or a line of bytes (eg. a ASCII string).
The output stream is a Java buffered DataOutputStream.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConnect to the remote hostvoidUse this to disconnect from the remote host.intUse this to read the socket timeoutbytereadByte()readLine()Read a line of text.This reads the input stream byte-by-byte searching for a pattern.voidsetSocketTimeOut(int timeout) Use this to set the socket timeoutvoidWrite a string (it will be terinputStreamated with a carriage return and end-of-line).
-
Field Details
-
socket
Socket reference. -
outputStream
Output stream.
-
-
Constructor Details
-
NativeSock
public NativeSock()
-
-
Method Details
-
connect
public void connect(String host, int port) throws IOException, UnknownHostException, ConnectException Connect to the remote host- Parameters:
host- The remote hostnameport-- Throws:
IOExceptionUnknownHostExceptionConnectException
-
disconnect
public void disconnect()Use this to disconnect from the remote host. It closes the socket and the input/output streams. -
write
Write a string (it will be terinputStreamated with a carriage return and end-of-line). This will only work with ASCII characters.- Parameters:
s- The string to write.- Throws:
IOException
-
readLine
Read a line of text. This assumes the text is in ASCII format. The method returns the result if a carriage return\nis reached.- Returns:
- The resulting string.
- Throws:
IOException
-
readByte
- Throws:
IOException
-
readUntil
This reads the input stream byte-by-byte searching for a pattern. This only works with ASCII characters (8 bits).- Parameters:
pattern- The pattern to read until.- Returns:
- The input stream in string format upto the end of the pattern.
- Throws:
IOException
-
setSocketTimeOut
public void setSocketTimeOut(int timeout) Use this to set the socket timeout- Parameters:
timeout-
-
getSocketTimeOut
public int getSocketTimeOut()Use this to read the socket timeout- Returns:
- int
-