QB / QB64 Discussion Forum      Other Subforums, Links and Downloads      Archived Pascal Resources    Search
Respond to this messageReturn to Index
Original Message
  • I also wanted to make a foray into this...but never did.
    • stylez (no login)
      Posted Sep 24, 2003 5:39 PM

      What I would do is create some sort of simple packet system, to distinguish between a user attempting to send a file, and a user who's just sending text to the chat room. Something like:

      Public Enum PID_
          PID_TEXT
          PID_BEGINFILE
          PID_FILE
          PID_ENDFILE
          PID_ACK
      End Enum

      Public Type Packet
          id As PID_
          data As String
      End Type

      Dim f As Packet
      f.id = PID_BEGINFILE
      f.data = "somefilename.zip"
      'send f, wait for acknowledgement (PID_ACK) packet
      'open somefilename.zip
      f.id = PID_FILE
      'do
          'read a chunk of data into f.data
          'send f to remote computer
      'repeat until end of file
      'close file
      f.id = PID_ENDFILE
      f.data = chr(0)
      'send f
      '''etc


      Naturally, when receiving data, you'd have to check the id of the packet you've received to determine what you're going to do with it. If it's PID_FILEBEGIN, then you know that someone wants to send you a file, and you must open a file for output. If it's PID_FILE, but you've not received PID_FILEBEGIN, then something is wrong, or someone is trying to mess with your server. If it's PID_FILE, and you've got a file open for output, then you output the data to that file. If it's PID_ENDFILE, and the data is a null char, then you know you've received all of the file. And so on and so forth.

      You could expand on the packet much more, as well. One idea would be to add a source and destination to the packet, to enable two clients to directly transfer between one another, rather than wasting the server's bandwidth by making it a go-between.

      Anyway...that's what I would try, if I were to attempt file transfers, et al.

      Hope it helps/helped.
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Options Also send responses to my email address