private void ChooseAction(Socket s) throws IOException, ClassNotFoundException {
        ObjectInputStream in = new ObjectInputStream(s.getInputStream());
        Message msg = (Message) in.readObject();
        if (msg.getType().equals("CONNECT")) {
            mypeer.addNeighbor(msg.getHost(), msg.getPort());
        } else if (msg.getType().equals("SEARCH")) {
            LinkedList<PeerInfo> returnList = new LinkedList<PeerInfo>();
            /*search my files*/
            if (mypeer.searchMyFiles(msg.getFilename()) == true) {
                returnList.add(new PeerInfo(this.socket.getLocalPort(), String.valueOf(this.socket.getInetAddress())));
            }
            /*send request to neighbors except sender if ttl>0*/
            if (msg.getTtl() > 0) {
                for (int i = 0; i < mypeer.neighbours.size(); i++) {
                    if (!mypeer.neighbours.get(i).getUsername().equals(msg.getSender())) {
                        Socket socketToConnect = new Socket(mypeer.neighbours.get(i).getHost(), mypeer.neighbours.get(i).getPort());
                        ObjectOutputStream out2 = new ObjectOutputStream(socketToConnect.getOutputStream());
                        /*Send the request*/
                        Message msg2 = new Message("SEARCH", msg.getFilename(), null, 0, this.myusername, msg.getTtl() - 1, null);
                        out2.writeObject(msg2);
                        out2.flush();

                        /*Receive the response*/
                        ObjectInputStream in2 = new ObjectInputStream(socketToConnect.getInputStream());
                        Message msgres = (Message) in2.readObject();
                        
                        if (msgres.getType().equals("SEARCHRES")) {
                            for (int j = 0; j < msgres.getSearchres().size(); j++) {
                                returnList.add(msgres.getSearchres().get(j));
                            }
                        }
                        out2.close();
                        in2.close();
                        socketToConnect.close();
                    }
                }
            }
            /*send list to sender*/
            ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
            /*Send the request*/
            Message msgres = new Message("SEARCHRES", msg.getFilename(), null, 0, this.myusername, 0, returnList);
            out.writeObject(msgres);
            out.flush();
            out.close();
        } else if (msg.getType().equals("FILEREQ")) {
            String fileName = mypeer.getSharedFolder() + msg.getFilename();
            ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
            File myFile = new File(fileName);
            byte[] mybytearray = new byte[(int) myFile.length()];

            //Start a fileInputStream to read bytes from the requested file.
            //System.out.println("sdfd"+myFile);
            FileInputStream fis = new FileInputStream(myFile);
            BufferedInputStream bis = new BufferedInputStream(fis);

            //Read as many bytes as the size of the file to be sent.
            bis.read(mybytearray, 0, mybytearray.length);
            out.write(mybytearray, 0, mybytearray.length);
            out.flush();
            out.close();
        }
        in.close();
    }