Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. 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,041