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.

P2P Binary Data Transfer

Discussion in 'Multiplayer' started by shaun, Dec 27, 2007.

  1. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Larus, or anyone else who is a P2P guru - how would you recommend serializing a FileStream, byte array or something similar to send over P2P, and what kind of reliability methods would you put in place?

    I was thinking about indexing the packets and firing them out via RPC, but I remembered we are using UDP, or maybe RUDP (I'm not sure what you guys have done to Raknet under the hood) and sending a 1000 RPC calls per second might not be very nice.

    So I'd like to know if you have any suggestions for this before I blow up my client peers.

    Thanks :)
     
  2. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    274
    You don't need to slice and dice your data into packets. That is done automatically internally. At the moment you can send arbitrary data in a string parameter in an RPC function. However, this carries a 4K character limit, so you might end up needing to slice and dice your data after all. You could then, for example, just have an RPC function which has a string parameter, a chunk number and total chunk numbers. The chunks are buffered on the receiving end and the data can be created when all chunks have arrived. Sending 1000 RPCs with 4K of data each will have an effect on the network so you might limit yourself to doing only one or a few RPCs per frame update.

    benblo from Gamepulp has previously posted a method for sending objects using an XML serializer here: http://forum.unity3d.com/viewtopic.php?t=7514

    I know this is inconvenient but the next release of Unity will include byte array support where you can send any sized chunk of data in a single RPC call.
     
  3. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Thanks - The limit isn't so bad, as we can still get the job done nicely.
    I've built the basic RPC stuff to put the file in a byte array and send it over the network (it was based on the chat app, funnily enough) it just needs timing and reliability control.
    I'll post the result when it's useful :)
     
  4. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Larus,

    If you mean that the NEXT version wil be able to send byte arrays, then to what version are you pointing ? A 2.x pointrelease ?
     
  5. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    274
    I'm referring to 2.0.2.
     
  6. Ricko

    Ricko

    Joined:
    Dec 9, 2007
    Posts:
    169
    W00t! (I couldn't resist... that's good news)

    Ricko
     
  7. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    2.0.2 that is indeed GOOD news :)
     
  8. Loran

    Loran

    Joined:
    Nov 14, 2007
    Posts:
    124
    Hi,

    I'm new to networking side part and i was wondering if i could send/receive byte Array in the 2.1.0f5 version.

    What i want to do is to use some opencv tracking tech on a computer ( http://forum.unity3d.com/viewtopic.php?t=17868 ) and send a Vector3 Array to a 2nd comptuer who will do the graphical stuff so i need the fastest transmission ability.

    Tx.
     
  9. Loran

    Loran

    Joined:
    Nov 14, 2007
    Posts:
    124
    null
     
  10. Loran

    Loran

    Joined:
    Nov 14, 2007
    Posts:
    124
    i've tested :
    Code (csharp):
    1.  
    2. void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
    3.     Vector3[] test = new Vector3[4000];  // Don't need so much !!
    4.     for (int j = 0; j < 4000; j ++) {
    5.          if (stream.isWriting)
    6.              test[j] = Random.insideUnitSphere;
    7.  
    8.         stream.Serialize(ref test[j]);
    9.     }
    10. }
    11.  
    And so far, in local networking with sendrate @ 15 , it seems like it 's doing fine...


    Each times i discover a new aspect of Unity, i feel like working on the best solution ever made. I'm glad that the next release comes to Windows vista. I bet Unity is going to have a hudge succes.
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    That code will definitely not work for anything near realtime ...

    thats 3000 * 12 byte per send, thats 36000 bytes or 36kb per send

    so with a send rate of 15 thats 540kb + overhead per second per player in your P2P network on the upstream end, the downstream end is numPlayer times that value.

    You definitely need to seriously cut what you intend to send there.
     
  12. Loran

    Loran

    Joined:
    Nov 14, 2007
    Posts:
    124
    This was just an incoming test....
    My purpose is to not to make GAMES. It 's just exchanging process behaviour between several computers on a local network.

    I'll keep inform about my testing straight forward.

    Tx for reading ;)
     
  13. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Fast forward 5 years... still no byte[] support?
     
  14. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    byte[] is supported, it's just not documented.
     
  15. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ah, ok thanks!