I'm writting some code, to search in the network for online instances and share files between them. The user selects an instance and fill a field with the name of the file to look for (variable "searchName"). After this the system serialize the object and retrieve it to user instance. But i need to get the path of where the file is located on the other online instance.
Here is my sendData and ReceiveData, both methods are working, i receive a workbook and i can see it, but i really need to know where the file is located on the other instance that its sharing the file
public boolean sendData(String ip, String searchName, String pattern) throws IOException, UnknownHostException, ClassNotFoundException {
Socket aux;
String destinationIP = "";
int port = 0;
for (AddressServiceTypePair aux_pair : onlineApps) { //get the ip and port
if (aux_pair.getIP().equals(ip)) {
destinationIP = ip;
port = aux_pair.getPort();
}
}
if (!ip.equals(destinationIP)) {
return false;
}
SocketAddress a = new InetSocketAddress(destinationIP, port); //Configure connection
aux = this.networkController.getNewSocket();
aux.connect(a);
ObjectOutputStream data = new ObjectOutputStream(aux.getOutputStream());
data.writeObject(searchName); //Search for the file on the other instance with certain name
data.flush();
ObjectInputStream data2 = new ObjectInputStream(aux.getInputStream());
Workbook answer = (Workbook) data2.readObject();
aux.close();
if (answer == null) {
return false;
}
return true;
}
public Workbook receiveData(String s) throws FormulaCompilationException, IOException {
Workbook[] workbooks = uiController.getWorkbooks();
for (Workbook wb : workbooks) {
if (uiController.getWorkbookFileName(wb).equals(s)) {
return wb;
}
}
return null;
}