Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    3,582