Java Reference
In-Depth Information
...
private void sendAndReceive() {
IpcClientConnection ipcConn;
try {
ipcConn = IpcClientConnection.openConnection(MY_NATIVE_SERVER_PORT);
// send command
ipcConn.sendCommand(cmd);
// receive response
res = ipcConn.receiveResponse();
} catch (Exception e) {
e.printStackTrace();
}
}
So the steps to perform are:
1. Open an IPC client connection.
2.
Send an IPC command.
3. Read the IPC response.
4. Process the data received.
For the sake of clean code and encapsulation, we create command
and response classes:
public class IpcMessage {
private byte[] data;
public IpcMessage(byte[] data)
{
this.data = data;
}
byte[] getBuffer() {
// TODO: handle buffer according to protocol
return data;
}
} // TODO: implement derived classes according to protocol
public class IpcResponse extends IpcMessage
{
...
} public class IpcCommand extends IpcMessage {
...
}
We define the base class for all IPC connections, which provides
low-level synchronous bi-directional communication:
public abstract class IpcConnection {
private final InputStream in;
Search WWH ::




Custom Search