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

[Release] FM Network UDP: Easy Server-Clients Networking

Discussion in 'Assets and Asset Store' started by thelghome, Sep 2, 2019.

  1. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    FM Network UDP provides you a simple, flexible networking solution using UDP
    Webpage | Asset Store

    UDP Networking With Simple Commands:
    FMNetworkManager.instance.SendToAll("Hello World");
    FMNetworkManager.instance.SendToOthers("Hello World");
    FMNetworkManager.instance.SendToServer("Hello World");
    FMNetworkManager.instance.SendToAll(byte[]);
    FMNetworkManager.instance.SendToOthers(byte[]);
    FMNetworkManager.instance.SendToServer(byte[]);

    # Auto Network Discovery & Connect
    # Simple Send & Receive with Message or Byte[]
    # Smooth Sync Network Objects
    # Server <=> Clients
    # General Send Type: All, Server, Others
    # Cross Platform: iOS/Android/Mac/PC
    # All Written in C#, easy to modify if necessary.
    *We also provided advanced streaming solution in FM Exhibition Tool Pack

    Support: thelghome@gmail.com

    FMNetwork1-100.jpg
    FMNetworkUDP.png
    FMNetwork3-100.jpg



    [Sharing our recent developments]
    Small improvement for this old motion capture system & this little UDP tool works well.
     
    Last edited: Jun 7, 2020
    LevonRavel likes this.
  2. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    It is proud to apply FM Network UDP for LEONARDO DA VINCI exhibition in Hong Kong!
     
    PutridEx likes this.
  3. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    [v1.097] updates
    -Added Large File Sender Example
     
    Last edited: Nov 15, 2019
    andrew210 likes this.
  4. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Oculus GO Live Streaming Demo with FM Network UDP
     
  5. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    Hi. I am trying to use this to connect an app running on an Oculus Go headset with an Android tablet, but they dont want to connect. Im starting off with the demo scene, starting one as the Server / one as Client, but the two apps dont find each other. I was expecting the AutoNetworkDiscovery would handle this? With my use case I wont be able to specify in advance what the IP will be, so I really need them to find each other automatically. On the Client the value for IsConnected switches to True for a couple of seconds and then reverts to False.
    Am I missing something here? Thanks for any help with this.
     
    Last edited: Dec 15, 2019
  6. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    okay, got them to talk to each other!
    Just need to work out
    1) how to send a snapshot of the current view from the client headset to the server tablet and
    2) how to send commands from the server to client, for changing the scene, configuration etc (an RPC I guess?)
    Are these both possible with this version, or should I be using the full pack (I bought both)
    Many thanks
     
    Last edited: Dec 16, 2019
    thelghome likes this.
  7. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Q1:
    You may refer to GameViewEncoder/Decoder.cs, if you want to capture snapshots only. The sample scene is in our full pack.

    Q2:
    Our network systems support below behaviour.
    SendToAll()
    SendToOthers()
    SendToServer()

    We might include some minimal multiplayer game demo scene in future.

    PS: we are on our holiday period til 24th December. Sorry about the late reply.
     
  8. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    Thanks for your help, much appreciated! Asset looks great so far, clean code and well documented.
    I can see how it all works when everything is in one scene, but Im having problems seeing how to keep the connection across multiple scenes. My project needs to switch scenes. I use SendToOthers() to get the scene switched, but then there is no connection to the Server in the next scene. I note in your demo project you dont change scene after AssignasServer/Client...

    I have tried a couple of routes - adding a NetworkManager object to the new scene (fails) and using DontDestroyOnLoad from the init screen (also fails)
    So, Im wondering if you know what the best practise is for keeping a connection with your network object between scenes?
    Many thanks, and seasons greetings
     
  9. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Sorry for late reply, during the holiday period.

    Some of suggested ways:
    1. Try, Async Load scene
    2. Don’t destroy the network objects between scenes
    3. Never create network manager twice
     
  10. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    Hi,
    Thanks for the response.
    I have started with your demo scene, and adapted it so that the Server / Client buttons go to a second scene using LoadSceneAsync.
    The FMNetworkManager object is retained through to the second scene via DontDestroyOnLoad.
    Unfortunately, the connection doesnt work. The IsConnected value switches to False after a couple of seconds on the second scene.

    Is it not possible to retain the connection between scenes with your asset?
     
  11. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Are you testing them(Server & Client) on one computer only?

    In one of my projects, I used "LoadSceneMode.Additive" for my second scene without any connection issue.

    PS: We will try to reproduce your issue on our side asap. sorry for the inconvenience during the holidays, as we are out of town.
     
  12. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    Hi,
    Thanks for the reply.
    I am testing on android phone (server) to oculus go (client) which didn't work.
    Then tried android phone (server) to pc (client) which also fails.
    Really need to know if its possible to achieve this or not with your assets.
    A sample project would be really helpful.
     
  13. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Could you send us an email for technical support?

    We will try to reproduce the issue on our side asap, and hopefully a sample scene will be ready soon.

    Support email: thelghome@gmail.com
     
  14. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    In FMNetworkManager.cs, please replace the Awake() with below script.
    It's tested on Macbook and works fine. and We will test on other devices soon.

    Code (CSharp):
    1.  
    2. //It also works when you switch scene with below function too.
    3. //UnityEngine.SceneManagement.SceneManager.LoadScene(SceneName);
    4. //Please be noted:
    5. //DontDestroyOnLoad only work for root GameObjects or components on root GameObjects.
    6.  
    7. void Awake()
    8. {
    9.     if (instance == null)
    10.     {
    11.         instance = this;
    12.         this.gameObject.transform.parent = null;
    13.         DontDestroyOnLoad(this.gameObject);
    14.     }
    15.     else
    16.     {
    17.         Destroy(this.gameObject);
    18.     }
    19. }
    20.  
     
    Last edited: Dec 25, 2019
  15. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    Many thanks. I will try that today. I was using dontdestroy within my own script (finding the network object by name and then DontDestroyonload) so maybe that was an issue? Also, I wasn't using loadscene additive, I am using loadasync.
    I will make some changes and if that doesnt work I will send a mail to support.
    Cheers guys
     
  16. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    that worked, many thanks :)
     
  17. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
    @thelghome want to know support Reliable UDP?thanks
     
  18. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    It's non-reliable UDP. If you need reliable solution, will you consider TCP or WebSocket?
    full pack: http://u3d.as/1uHj
    we have live streaming examples in UDP/TCP/WebSocket.
     
  19. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
    thanks,Can your consider adding rudp? I have frequent rpc calls for tasks, important tasks rudp is very important
     
  20. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    I suggested that you can implement some “confirmation” method yourself for important tasks.

    For example, I can sync multiple video players without rudp(in a panorama projection setup).

    To achieve this, I will send a round trip command for confirm the status/important task.
     
  21. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
    thanks. I have purchased your plugin.
     
  22. ars_thanea

    ars_thanea

    Joined:
    Dec 6, 2019
    Posts:
    1
    Hey, I bought this plugin today and I have a question: I'm trying to send texture as an array of bytes from client to server. To do this I use LargeFileEncoder/Decoder. The data is sent but the server only receives events Action_ProcessByteData (im working on the sample scene provided) and the event from LargeFileDecoder (OnReceivedByteArray) is never called. Do you have any idea why is that? Can you explain how should I use the LargeFileEncoder/Decoder? I cannot find any information in the documentation.
     
  23. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    You may probably need to reduce the traffic, by reducing the speed of sending. I believe that I’ve replied your email with suggested methods. If not, please don’t be hesitated to send us email.
    support email: thelghome@gmail.com
     
    Last edited: Jan 28, 2020
  24. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    [version 1.120] updated
    - New Layout Skin for inspector, Optimised scripts
    FMNetworkUDP.png
     
  25. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    We started working on few free tutorial on our YouTube Channel, this is one of related example with FM Network UDP.
    [Tutorial] Sync Network Objects (Beginner)
    full tutorial: https://youtu.be/K6kWLszpykM

    This is a step by step Unity3D tutorial for beginners.
    In this video, we are going to sync the bananas in networking.
    In order to synchronise your transformation, you have to convert all position and rotation into bytes.
    On the other side, all those received bytes should be convert into position and rotation for each game object.

    Once you understand the logic, you can master on any kind of data streaming.
     
  26. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
  27. jingray

    jingray

    Joined:
    Feb 6, 2015
    Posts:
    53
    Can I start multiple server with multiple client ?!
    Others client can join with "ID", like Lobby ?!
     
  28. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Yes, it depends on IP and port.
    In one computer, you can start multiple servers with different ports. Multiple clients with different local IP can connect to them.

    If you are testing on one computer, you can have maximum 1 server and 1 client for the target port.
     
    jingray likes this.
  29. CONGOBILL

    CONGOBILL

    Joined:
    Mar 4, 2020
    Posts:
    17
    Can I start a server and receive the UDP stream through ffplay or VLC?
     
  30. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    It's not compatible with VLC at the moment, as it's a customised streaming solution between Unity apps, and html.
     
    CONGOBILL likes this.
  31. uneedtee

    uneedtee

    Joined:
    Jun 22, 2017
    Posts:
    5
    I am trying to use FM network UDP for a hololens 2 shared space experiance.
    I have some problems with receiving the world anchor byte array using the largefile en-and decoder.
    Is it right that your decoder only delivers chunks of the array, which i have to rebuild by myself or am i doing something wrong?
    Grreat solution btw, hope i can get it to work with your(or any) help.
     
  32. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    It will split the byte[] into smaller chunks. Please check if you have proper setup of encoder and decoder between devices. The label ID will work as pairing for them.
     
  33. uneedtee

    uneedtee

    Joined:
    Jun 22, 2017
    Posts:
    5
    I receive the chunks but have problems to rearange them to the original large file. im trying to append them to a list to convert it later back to the large array, but that seems not to work as nothing is added. Also tried to write the chunks into a file with filestream but the file also stays empty.

    Code (CSharp):
    1.  
    2.  
    3. public List<byte> importingAnchorBytes = new List<byte>(0);
    4. public byte[] importetAnchor;
    5.  
    6. public void Action_ProcessByteData(byte[] _byte)
    7.     {
    8.         if (FMNetworkManager.instance.NetworkType == FMNetworkType.Server)
    9.         {
    10.             if (ServerText != null) ServerText.text = "Server Received byte[] : " + _byte.Length;
    11.             Debug.Log("incoming");
    12.             importingAnchorBytes.AddRange(_byte);
    13.             //AppendAllBytes(GetWorldAnchorsDataPath(), _byte);
    14.         }
    15.             else
    16.         {
    17.             if (ClientText != null) ClientText.text = "Client Received byte[]: " + _byte.Length;
    18.         }
    19.     }
    20. public void LaterToDo()
    21. {
    22. importedAnchor = importingAnchorBytes.ToArray();
    23. }
    24.  
    25. private static void AppendAllBytes(string path, byte[] bytes)
    26.     {
    27.        
    28.         using (var stream = new FileStream(path, FileMode.Append))
    29.         {
    30.             stream.Write(bytes, 0, bytes.Length);
    31.         }
    32.     }
    33.  
    34.  
     
  34. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Our LargeFileDecoder should help you combining all the chunks back to your original byte[] array. You shouldn't have to do it manually. Please check the usage of our demo scene "Demo_FMNetworkBasic".

    The general setup would be like this:
    Sender: LargeFileEncoder -> OnDataByteReadyEvent() -> FMNetworkManager (SendToAll/Others/Server)
    Receiver: FMNetworkManager -> OnReceivedByteDataEvent(byte[]) -> LargeFileDecoder

    You may also check if you receive any byte via OnReceivedByteDataEvent(byte[]).
     
  35. uneedtee

    uneedtee

    Joined:
    Jun 22, 2017
    Posts:
    5
    I have tried the demo scene with two fresh projects and fresh imported asset.
    If I send the large file from server, the server text shows the original large size and the client text only a chunk size.
    If I send the large file from client, both texts only show chunk sizes.
     
    Last edited: Aug 4, 2021
  36. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    It seems likely that you have UDP loss during large file streaming.
    It may happen when you are in bad wifi environment, or it exceeds your router buffer sometimes.

    The suggested method would be increasing "Add DelayEvery Packet" value. It may take longer time to complete, but should be more stable for large files.

    and please be noted that, the streaming result will be interfered if you keep sending large files multiple times(before the previous one complete).
    Screenshot 2021-08-05 at 7.08.36 PM.png
     
  37. system-idle

    system-idle

    Joined:
    Dec 13, 2013
    Posts:
    26
    Hi there

    With UNet I could run multiple instances of clients on the same IP (1 PC).
    With FM Network only 1 client can join running on same PC. I'm assuming this is because the IP is the same.
    How can I run multiple clients on the same machine for dev testing?
     
  38. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    Due to the IP limit, it's not available for local test of many clients with FMNetworkUDP.
    The alternative will be using FMWebsocket, which doesn't have limit on local clients count on single machine.
    https://u3d.as/1DH3
     
  39. system-idle

    system-idle

    Joined:
    Dec 13, 2013
    Posts:
    26
    Thanks, I'd rather not use websockets.

    Is there any way I can remove the IP limit?

    I tried editing the code, but it seems the plugin is not using localIP from the C# code as it still doesn't allow clients to join.
     
  40. system-idle

    system-idle

    Joined:
    Dec 13, 2013
    Posts:
    26
    Otherwise, can you organise a refund please?
     
  41. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    In the current version, it registers clients via IP & Port.
    The only way to unlock IP limit is setting up multiple FMNetworkManager with different ports.

    PS: You may reach us via email, if you have concerns about technical support or refunding: thelghome@gmail.com
     
    Last edited: Dec 9, 2021
    system-idle likes this.
  42. dawnr23

    dawnr23

    Joined:
    Dec 5, 2016
    Posts:
    41
    Server: Android Galaxy S7 Tap (1 pc)
    Client: Oculus Quest2 (20ea)

    I'm trying to connect 21 devices with the same platform as above.

    The function of the server device is to share the game screen of the client, and only one game screen sharing will be carried out individually. (You don't need to watch your 20s at the same time)

    Is it possible with this asset to implement the above?

    *Additional question. Can I see all 20 screens at the same time on the server device?
     
  43. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    For monitoring multi users' game views, it requires encoders with FMETP STREAM.
    I assumed that it's for monitoring purpose, which you may keep connection with multiple devices in local network.

    In server app, you may send command to your target clients and request for "enable GameViewEncoder".
    In general use case, you can have 20 screens with thumbnail resolution in lower fps, and only increase the streaming quality/fps of your target device via udp command.
     
  44. ibompuis

    ibompuis

    Joined:
    Sep 13, 2012
    Posts:
    100
    Hi,
    I use FMETP STREAM 3 with Oculus quest as server and surface tablet 7 as client, I would like send string event (button) to the quest with the tablet client (change content) , how can I do this ?
    Thanks
     
  45. thelghome

    thelghome

    Joined:
    Jul 23, 2016
    Posts:
    737
    You may use SendToServer() to send your string message. On the receiver side, you may write your own script to check the string message and define your own function or behaviour.

    or you can even send a json string with all properties, and change content based on your game logic.
     
    ibompuis likes this.