Results 1 to 8 of 8

Thread: Remote File Browser

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Remote File Browser

    I have started a project to make a remote file browser via TCP (pretty new in that area) and need some help now.

    What I have thought of is to set up an ArrayList on the remote machine client with this structure:

    Code:
    Folder1
        Name
        Size
        Last Changed
    Folder2
        Name
        Size
        Last Changed
    And then I do the same with the files.
    But the problem is how to transmit this arraylist. Should I make a long string out of the arraylist and set it or what should I do? :S

    Any tip is welcome

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Remote File Browser

    Transmitting objects over a network connection is exactly the sort of thing that serialization exists for.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Remote File Browser

    thx for pointing me to the right direction
    I followed a tutorial on that subject and have now succeeded in serializing a list of directoryinfo and writing it to a file. Then I read it again to check if it worked, and it did.

    So next problem. I am now going to send this over TCP. The problem is, I have set up my TCP so I send messages with a StreamWriter, so I have like 2 options, write and writeline. Do I need to change so I have a binarywriter or something?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Remote File Browser

    A StreamWriter simply sits on top of a Stream and writes to it, so you must already have a Stream. Presumably it's a NetworkStream, but the type is irrelevant. When you searialise, whether binary or XML, you can pass a Stream to the Serialize method. You simply pass the Stream you already have. If you no longer need the StreamWriter then get rid of it. If you still need it then keep it. It doesn't matter either way because it's irrelevant to the serialisation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Remote File Browser

    I passed the StreamWriter.Basestream which is a NetworkStream as you said.

    I tried serializing to that stream and I think it worked. It is the same stream I use for my chat with the remote user so I got some output in the chat.

    But what I want to do now is deserialize this.

    The problem is, how do I know when to deserialize whats coming in the stream and when to not?
    And how do I know into what to deserialize it to? (For example is I am sending lists of both DirectoryInfo and FileInfo)

    Thx for the help so far.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Remote File Browser

    You need to define a protocol. If you're sending different types of messages then you need to send information that describes the message so that the receiver knows how to interpret the message. At its simplest, this metadata would consist of a single Byte, allowing you to send 256 different types of messages. The sender would first send the appropriate Byte value to describe the data it was about to send, then it would send the data. The receiver would read the first Byte and then know how to interpret the data that followed. You might find that you need a more complex header, e.g. you might also want to send the size of the data as well as the type.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Remote File Browser

    This was a little harder...

    This is the code that serializes my List:

    Code:
                Stream stream = srReceiver.BaseStream;
    
                BinaryFormatter bformatter = new BinaryFormatter();
    
                bformatter.Serialize(stream, dirlist);
    So I am supposed to write first a single byte to the stream and then for example deserialize it to a List?
    How should I write that single byte? Because I should do it at the same time as writing the serialized data right? Like at the beginning of the data. It reads the first byte and then continues with the rest of the data doing it the right way. Or should I first write a single byte to the stream, then the reader reads that byte and goes into a special mode so it deserializes all data that it receives?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Remote File Browser

    You're not supposed to write a single Byte specifically. You're supposed to write whatever you decide you need to write to allow the receiver to determine what it's about to receive and process it accordingly. If you decide that that's a single Byte then write a single Byte. If it's something else then write something else. It's for you to define your own protocol.

    As for how you write it, you just write it, just as you do any other data. When reading, you just read it. You're trying to make it more complicated than it is. It's just data. You write and read it like any other data.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width