Running a REST server in Unity3d

I am trying to create a REST server as part of a Unity project, and at first thought that Nancy seemed an obvious choice. However, many headaches are later, and I still cannot get Nancy to work in the Unity Mono runtime - I can compile and run with Xamarin, but Unity gives me a pretty useless result, and I'm trying to use this asset:

Internal compiler error. See the console log for more information. output was: Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded. at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool) at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0 at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0 at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0 at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0 at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 

I can’t be the only person who has tried something like this, and I want to use it in several projects, so having something reusable has high priority - someone has successfully implemented something like that, and if so you can Do you give me any directions?

I would really like Nancy to work, but another way to easily embed a REST server would be just as valuable.

+8
rest unity3d nancy
source share
3 answers

According to this thread on Unity Answers , this happened because the .NET subset that uses Unity did not include System.Web, so copying the .Web.dll system v2.0.50727 to solve this problem.

However, if the memory serves, I recall a parameter in Unity to force it to use the full .NET 2.0 runtime rather than a subset, which may also solve the problem. Some time has passed since I used Unity, so the option could be removed.

Edit: See here called the "compatibility level".

Edit 2: In Player Settings

0
source share

I never managed to get an HTTP server running in a single client (the accepted answer looks correct, but it was too late for me to check it, let me know if it does not work) it seems that at least in unity 4 the necessary parts of mono performance. Things can be different in unity 5, I do not work with unity at the moment, so I'm afraid I'm not in the know.

Given this, the solution I chose - it is a client-client for listening with an external server - this works quite well, however, everything becomes a little more complicated than necessary.

Another solution that I heard about later is to use the Thrift protocol, there is an example at https://github.com/amilstead/unity3d-thrift-twisted , which should be sufficient to get started and support Thrift in a variety of languages, idioms are a bit differ from idiotic ones, but in general it will most likely be better suited for most cases when you need a built-in http server.

0
source share

All Articles