Package org.jrd.backend.communication
Class Communicate
- java.lang.Object
-
- org.jrd.backend.communication.Communicate
-
public class Communicate extends java.lang.ObjectThis class opens a socket and contain methods for read and write to socket IS/OS.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.BufferedReadercommInputprivate java.io.BufferedWritercommOutputprivate java.net.SocketcommSocketstatic java.lang.StringNO_VALLUE_DONE_RESULTstatic java.lang.StringNO_VALUE_OK_RESULT
-
Constructor Summary
Constructors Constructor Description Communicate(java.lang.String host, int port)Constructor creates a socket on given port and saves the streams into class variables.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes a socket.voidprintln(java.lang.String line)Sends a line with request to agent.java.lang.StringreadResponse()Method that reads agent's response.private java.lang.StringtrimReadLine()
-
-
-
Field Detail
-
NO_VALUE_OK_RESULT
public static final java.lang.String NO_VALUE_OK_RESULT
- See Also:
- Constant Field Values
-
NO_VALLUE_DONE_RESULT
public static final java.lang.String NO_VALLUE_DONE_RESULT
- See Also:
- Constant Field Values
-
commSocket
private java.net.Socket commSocket
-
commInput
private java.io.BufferedReader commInput
-
commOutput
private java.io.BufferedWriter commOutput
-
-
Method Detail
-
close
public void close()
Closes a socket.
-
trimReadLine
private java.lang.String trimReadLine() throws java.io.IOException- Throws:
java.io.IOException
-
readResponse
public java.lang.String readResponse()
Method that reads agent's response.- Returns:
- "ERROR" in case of fail or corresponding bytes or class names
-
println
public void println(java.lang.String line) throws java.io.IOExceptionSends a line with request to agent.- Parameters:
line- "CLASSES" or "BYTES className"- Throws:
java.io.IOException- if the write operation fails
-
-