Results 1 to 4 of 4
  1. #1
    Iman is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Help on sending a directory file over a socket

    Hi,

    I am developing a file sharing client-Server application. I need to send the client directory to the server. Jtree is a structure and I was not able to use it to send the file structure for the client. Any suggestions, please advice.

    Regards,
    Iman

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Help on sending a directory file over a socket

    One way would be to define your own protocol to describe the directory structure.
    There might be a way to describe the structure using classes in anther class and then serialize and send the containing class.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Iman is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: Help on sending a directory file over a socket

    Thanks a lot Norm.
    I have used the follwing two methods that helped me to construct DefaultMutableTreeNode and send it over a socket as an object. The returend object is DefaultMutableTreeNode
    DefaultMutableTreeNode CreateTree ()
    {
    String myfile = ("C:\\");
    Fullpath =myfile+"TmpDir";
    File file=new File(Fullpath);
    boolean exists = file.exists();
    if (!exists)
    {
    // It returns false if File or directory does not exist
    try{
    // Create one directory
    boolean success = (new File(Fullpath)).mkdir();

    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }
    // Create a local user tree
    root = new DefaultMutableTreeNode(username.getText(), true);
    getList(root,new File(Fullpath));
    return root;
    }
    public void getList(DefaultMutableTreeNode node, File f) {
    if(!f.isDirectory()) {
    if (f.getName().endsWith("")) {
    DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
    node.add(child);
    }// end if
    }//end if
    else {
    DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
    node.add(child);
    File fList[] = f.listFiles();
    for(int i = 0; i < fList.length; i++)
    getList(child, fList[i]);
    }
    }//end get list

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Help on sending a directory file over a socket

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Sending a JPEG file over a tcp socket and saving it
    By busdude in forum New To Java
    Replies: 0
    Last Post: 12-02-2010, 10:31 PM
  2. Sending and splitting an image file over tcp socket.
    By busdude in forum Advanced Java
    Replies: 1
    Last Post: 12-02-2010, 11:03 AM
  3. Problems with sending zip file using Socket
    By morita in forum Networking
    Replies: 0
    Last Post: 05-14-2010, 07:41 PM
  4. Sending a file through socket
    By sureshkumarcs88 in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 08:32 AM
  5. Replies: 1
    Last Post: 02-10-2009, 10:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •