Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TCP fragmentation? (@ 1448 bytes)

Discussion in 'Multiplayer' started by MentalFish, Mar 22, 2014.

  1. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
    Whenever I try to receive longer feeds from a TCP connections, it comes in split in two, with one missing character in between. The first portion of the feed I am not sure why this is occurring as I have set READ_BUFFER_SIZE to 4096 (or even 8192) when using TcpClient.

    Looking up TCP and the number 1448 these issues pop up:
    http://en.wikipedia.org/wiki/Goodput

    "Imagine that a file is being transferred using HTTP over a switched Ethernet connection with a total channel capacity of 100 megabits per second. The file cannot be transferred over Ethernet as a single continuous stream; instead, it must be broken down into individual chunks. These chunks must be no larger than the maximum transmission unit of Ethernet, which is 1500 bytes. Each packet requires 20 bytes of IP header information and 20 bytes of TCP header information, so only 1460 bytes are available per packet for the file transfer data itself (Unix systems[citation needed], Linux, and Mac OS X[1] are further limited to 1448 bytes as they also carry a 12-byte time stamp)."

    The same game, running in a different game engine, handles the lengthy TCP data just fine.
     
  2. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    That sounds like you've got an off-by-one error in your code...

    TCP is a *stream* based protocol, not a *packet* based one. From a paradigm perspective you could set your buffer to 1MB and still get your data in single byte reads.
     
    Last edited: Mar 23, 2014
  3. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
    Thanks a bunch. I assumed it was an off by one from the second portion of the incoming data, but it seems to have been a missing last character of the first, which is now remedied. Now, for some stitching of pieces to take place... :cool:
     
    Last edited: Mar 23, 2014