Search Unity

accessing c++ socket code from C# Unity

Discussion in 'Connected Games' started by simplysimm, Jan 21, 2014.

  1. simplysimm

    simplysimm

    Joined:
    Dec 5, 2013
    Posts:
    15
    So I have a C++ library which uses native bsd sockets that I'd written for some other client a while back. I want to use this in Unity too and access it to/from C## code. I assume I will have to write a native plugin and then interact with from Unity C# code. Its not something I've done before (I've written either only C++ or only managed code projects) so not sure how it works.

    Before I get started - I wanted to clarify what this page is trying to say http://docs.unity3d.com/Documentation/Manual/Plugins.html

    What does Pro/Mobile only mean here? Only the Pro/Mobile Unity builds can access my native plugin? I don't have Unity pro and want my access to my native library from all Unity targets (Web/Mobile/PC/Mac). Whats the best way to go?

    I took a look at https://github.com/fholm/udpkit to see how that works. It doesn't have a readme/steps for a beginner like me so I couldn't understand much from it. I'm sure its great for folks who are versed with working with native plugins from managed code.

    Also I am OK with using the C++ source directly if possible in Unity - I guess its not possible and it must be a compiled library.
     
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,043
    Like you discovered yourself, my library UdpKit does this (interface with native plugins for socket support on non-pro versions), I am not sure you could ask for a better reference then code which implements literally what you ask for? What do you want us to help you with that reading the UdpKit sources dont?
     
  3. simplysimm

    simplysimm

    Joined:
    Dec 5, 2013
    Posts:
    15
    Hi fholm, also wanted to know the following

    http://docs.unity3d.com/Documentatio...l/Plugins.html
    What does Pro/Mobile only mean here? Only the Pro/Mobile Unity builds can access my native plugin? I don't have Unity pro and want my access to my native library from all Unity targets (Web/Mobile/PC/Mac). Whats the best way to go?

    Is there a way I can compile C++ sources directly and refer them in Unity or it must be in the form of a compiled library?
     
  4. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,043
    Unity without Pro for Desktop platforms can not access Native Plugins.
    Unity without Pro for Mobile platforms can access Native Plugins.
     
  5. simplysimm

    simplysimm

    Joined:
    Dec 5, 2013
    Posts:
    15
    OK I'm on "without Pro" and want to build for Desktop and Mobile so I'll have to use different libraries for both (native for mobile and managed for desktop). Ugh - thats what I was afraid of. Thanks fholm for clarifying and your quick response :)
     
  6. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,043
    This is exactly what UdpKit does.
     
unityunity