Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: network programming

  1. #11
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    My advance so far: I have used read() to read from a file in a given block size and put that data in a struct. What happens if my block size is bigger that the whole file I am reading from?
    Will my struct be filled with the actual contents of the file and then random data will be added. or zeroes added?
    The protocol I'm implementing splits a file in 60k blocks, and it identifies the last packet as one with less than 60k of data.

    thnks
    J

  2. #12
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    Well, it depends how exactly your "putting your data in a struct" but you probably will have random data (perhaps 0s, depending on the OS and/or malloc, and previous allocations...).

    Generally you'll want to have a header for each packet (datagram) with the packet id and data length, and optionally but preferably a checksum to make sure your file is intact when all is said and done...

    While it's true that the max for a datagram is technically 64K, that does imply fragmentation (at best) or the datagram being dropped (if the router doesn't want to frag...) or more chances of loosing a packet fragment in route...

    You might want to check the code of a TFTP implementation to see all everything's done (and perhaps copy your whole implementation from a BSD licensed source if you feel like it!)


    Ammo
    Credit travels up, blame travels down -- The Boss

Posting Permissions

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