Java Reference
In-Depth Information
private final OutputStream out;
{
IpcConnection(InputStream in, OutputStream out)
this.in = in;
this.out = out;
}
// Generic IPC operations
protected void send(byte[] serializedCommand) throws IOException {
out.write(serializedCommand.length);
out.write(serializedCommand);
out.flush();
}
protected byte[] receive() throws IOException {
int responseLength = in.read();
byte[] responseBuffer = new byte[responseLength];
int read = 0;
while(read != responseLength) {
read += in.read(responseBuffer, read, responseLength - read);
} return responseBuffer;
}
}
We define the IPC client-side connection class which can be returned
from the static factory method IpcClientConnection.openCon-
nection() when it is called with the remote IPC server port parameter:
public class IpcClientConnection extends IpcConnection {
private final StreamConnection sc;
private IpcClientConnection(StreamConnection sc) throws IOException {
super(sc.openInputStream(), sc.openOutputStream());
this.sc = sc;
}
public static IpcClientConnection openConnection(int ipcServerPort)
throws IOException {
StreamConnection sc = (StreamConnection)Connector.open
("socket://127.0.0.1:" + ipcServerPort,
Connector.READ_WRITE, false);
return new IpcClientConnection(sc);
}
// IPC operations
public void sendCommand(IpcCommand cmd) throws IOException {
super.send(cmd.getBuffer());
}
public IpcResponse receiveResponse() throws IOException {
return new IpcResponse(super.receive());
}
}
Search WWH ::




Custom Search