I made a cross platform (Linux, Windows, Mac) UPDSocket class in c++ that I am using for a server. It sends and receives fine, I’ve tested it cross platform, ect. But now I’m wondering if I would be able to implement it into Unity as a native plugin, to reuse code and work from a single code base, or if I’d be better off using a separate System.Net.Sockets solution?
I know I’m answering my own question here, but it seems like using a System.Net.Sockets implementation is way simpler. Because c++ and C# have a vastly different concept of what a class is, you can’t simply convert one to the other. Well, correction, you CAN, but it seems like a lot of hassle to go through when C# has a perfectly good socket implementation built in.
To use native code in .NET, you first have to create a managed class wrapper. From there, you can import the DLL files into your Plugins folder under Assets. While doable, it’s a lot of work to accomplish what .NET has already accomplished for you with UDP sockets. If it was me, I’d just stick to .NET unless there’s lower level optimizations that need to be obtained.