0

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;
    } 
Joseph
  • 159
  • 2
  • 4
  • 12
  • There is no file, your data is in memory. You must persists it first somewhere. – tak3shi Jun 22 '16 at 14:41
  • So you are saying that i need to use FileInputStream instead? ... but i will search the file in other instance (even if i dont want to create the file, as you said its in memory), the file exists in other instance, i just want the path of the file in other instance ... i guess i dont need to save it as file in my instance to get the path of the file in other instance – Joseph Jun 22 '16 at 14:48
  • `if (!ip.equals(destinationIP)) `, that seems quirky. In network programming you first open a socket, no need to check for IP's. What is `AddressServiceTypePair ` ? – PeterMmm Jun 22 '16 at 14:57
  • AddressServiceTypePair its a class that associates a address to a service name ... has some method to get the HostAddress and get the InetAddress .. Its not an important class.. And if (!ip.equals(destinationIP)) it jsut to dont find myself in the list of online apps – Joseph Jun 22 '16 at 15:00
  • So you want the path from uiControler? I have no idea what uiControler is. – tak3shi Jun 22 '16 at 15:04
  • 1
    uiController its controller that helps the ui .. no i want the path that the file that when the system executes that line: "ObjectOutputStream data= new ObjectOutputStream(aux.getOutputStream()); data.writeObject(searchName); data.flush();" ... Here the system looks for a file with a certain name and serialize it, and a i want to retrive the path ... or should i been looking for the method receiveData? I guess the send only "cares" about the other online instance that has the file and the receiveData only "cares" about my instance – Joseph Jun 22 '16 at 15:20

0 Answers0