Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Create a custom native network plugin

Discussion in 'Connected Games' started by unity_iKCco7B3xA1Ejg, Jun 14, 2018.

  1. unity_iKCco7B3xA1Ejg

    unity_iKCco7B3xA1Ejg

    Joined:
    Jun 14, 2018
    Posts:
    1
    Hi guys :) I'm a beginner with Unity!
    Today, I need some help to create a native plugin for implement my own network-api in C.
    Im familiar to TCP networks, and dont use the unity network API is a choice.

    My question is mostly related to the threads. My network plugin will work on another thread than the unity main thread. I heared somewhere that "unity doesn't love callbacks that happen outside its main thread, so you'll need some sort of queueing mechanism".

    Indeed, i was about to build my protocol; deserialized packets holded in structures that will be in some callback signatures. e.g void onFooBarMessage(size_t client_id, struct foo_bar_msg_t *msg). This callback will be finally defined from the unity C# and called by my network when receiving the concerned packet.

    It seems to be a bad practice for some multithread-rendering problems. So, is there anything unity built-in for that kind of problem? I discovered https://docs.unity3d.com/ScriptReference/GL.IssuePluginEvent.html that may solve the issue but, is this function callable from a native plugin ?

    My idea is to keep defining callbacks in C#, registering them into my plugin, and then execute them with IssuePluginEvent().

    Thanks. Romain
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    4,264