public class TCPSocketClient extends Object implements Runnable
Modifier and Type | Field and Description |
---|---|
private Socket |
clientSocket_
The client socket.
|
private int |
debug_ |
private static String |
DEFAULT_SERVER_HOST |
private boolean |
errorResponse_ |
private String |
host_ |
private DataInputStream |
is_
The input stream.
|
private Thread |
listener_ |
private boolean |
listening_ |
private PrintStream |
os_
The output stream.
|
private int |
port_ |
private boolean |
waitingForResponse_ |
Constructor and Description |
---|
TCPSocketClient()
default Constructor uses DEFAULTS from this class for IP and port.
|
TCPSocketClient(String hostName,
int portNum)
Instatiates the client with custom IP and port.
|
Modifier and Type | Method and Description |
---|---|
void |
closeSocket() |
Socket |
initSocket()
Initializes the socket, and associated in and out streams.
|
boolean |
isInit() |
private boolean |
isListening()
Confirms if a listener Thread has started and is running/listening for a server response.
|
private boolean |
isWaitngForResponse() |
boolean |
listenToSocket()
Starts the listener Thread, AFTER checking that everything is initialized and ready to go (initsocket).
|
static void |
main(String[] args) |
void |
run() |
void |
send(String message) |
void |
sendAndWait(String message,
int maxBlockTime_ms) |
private boolean |
setListening() |
private boolean |
setListening(boolean l)
Only a new thread should call this.
|
private boolean |
setWaitngForResponse() |
private boolean |
setWaitngForResponse(boolean l) |
void |
signalClose() |
private static String DEFAULT_SERVER_HOST
private int debug_
private Socket clientSocket_
private PrintStream os_
private DataInputStream is_
private int port_
private boolean listening_
private boolean waitingForResponse_
private boolean errorResponse_
public TCPSocketClient()
public TCPSocketClient(String hostName, int portNum)
public Socket initSocket() throws UnknownHostException, IOException
UnknownHostException
IOException
public boolean listenToSocket() throws IOException
IOException
public void signalClose()
public void closeSocket() throws IOException
IOException
private boolean setListening(boolean l)
private boolean setListening()
private boolean isListening()
private boolean setWaitngForResponse(boolean l)
private boolean setWaitngForResponse()
private boolean isWaitngForResponse()
public boolean isInit()
public void send(String message) throws IOException
IOException
public void sendAndWait(String message, int maxBlockTime_ms) throws IOException
IOException
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses