Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Sending Textures by Fragmentation

Discussion in 'Unity Transport' started by flecona, Aug 27, 2021.

  1. flecona

    flecona

    Joined:
    Jun 11, 2018
    Posts:
    10
    Hello.

    We are experimenting with Unity Transport to distribute different types of data among clients, one of such types would be a Texture2D, we can extract the raw bytes of the Texture to send it through the Network but it's much bigger than allowed.

    I can't find a guide on how to use the FragmentationPipeline correctly, I can only guess some things from the documentation but I've yet to make a working demo. Could you please point me in the right direction or show me an example of the correct implementation? Everything else is working great and seems pretty straight forward.

    Unity 2020.3.16f1
    Transport 0.8.0
     
  2. ElegantUniverse

    ElegantUniverse

    Joined:
    Sep 13, 2018
    Posts:
    76
    flecona likes this.
  3. flecona

    flecona

    Joined:
    Jun 11, 2018
    Posts:
    10
    Thank you for the suggestion! however the Textures and data I'm trying to transfer are generated in real time and I can't have them previously stored on a web server.

    Is Unity Transport not suited for such transfers? I would still like to learn to use the FragmentationPipeline.
     
  4. ElegantUniverse

    ElegantUniverse

    Joined:
    Sep 13, 2018
    Posts:
    76
    In my opinion , Unity Transparent is a good option for making a real-time game,but it depends on many things such as your game and your code.
    you want to send and receive the texture in real time, what is the size of each texture in byte ?
    And how many concurrent users are going to send and receive these information at the same time?
     
  5. flecona

    flecona

    Joined:
    Jun 11, 2018
    Posts:
    10
    The size is around 1,808,000 bytes and it would be enough to send it to one client but I want to send it as often as possible because it's updated constantly in real time
     
  6. ElegantUniverse

    ElegantUniverse

    Joined:
    Sep 13, 2018
    Posts:
    76
    there is a way to split your all bytes data by buffer.copyblock, check this link out .
     
    flecona likes this.
  7. flecona

    flecona

    Joined:
    Jun 11, 2018
    Posts:
    10
    Thank you, I'm currently implementing my own fragmentation for big messages and I will use copyblock as you suggested until I can find more information or documentation on the FragmentationPipeline.
     
    ElegantUniverse likes this.
  8. ElegantUniverse

    ElegantUniverse

    Joined:
    Sep 13, 2018
    Posts:
    76
    this is an example, hope this help.


    Code (CSharp):
    1.  
    2. //for sending every 4 bytes :
    3.  
    4. byte[] Allbytes = new byte[8];
    5.         byte[] midByte = new byte[4];
    6.         byte[] evByte = new byte[4];
    7.         midByte = BitConverter.GetBytes(whatever);
    8.         evByte = BitConverter.GetBytes(whatever);
    9.         Buffer.BlockCopy(midByte , 0, Allbytes, 0, 4);
    10.         Buffer.BlockCopy(evByte , 0, Allbytes, 4, 4);
    11.        NativeArray<byte> ConvertedByte = new NativeArray<byte>(Allbytes, Allocator.Temp);
    12.  
    13.         NetworkPipeline UnreliablePipline = _unreliablePipline;
    14.  
    15.         if (_clientDrive.BeginSend(UnreliablePipline, _networkConnection, out var _sendReliableData) == 0)
    16.         {
    17.             _sendReliableData.WriteBytes(ConvertedByte);
    18.             _clientDrive.EndSend(_sendReliableData);
    19.         }
    20.  
    21.  
    22. //for receieving every 4 bytes :
    23.  
    24. byte[] Allbytes = new byte[8];
    25.     byte[] midbyte= new byte[4];
    26.         byte[] evbyte= new byte[4];
    27.         Buffer.BlockCopy(Allbytes, 0, midbyte, 0, 4);
    28.         Buffer.BlockCopy(Allbytes, 4, evbyte, 0, 4);
    29.         int userid = BitConverter.ToInt32(midbyte, 0);
    30.         Int16 condition = BitConverter.ToInt16(evbyte, 0);
    31.  
    32.  
    33. // you can convert to string as below
    34. Encoding.ASCII.GetString(stringbyte);
    35.  
    36.  
     
    Last edited: Dec 26, 2021