NeoNetwork is a class library to provide a simple access to Unity3D's networking stack.
You can either use to copy the source files of this project into your Unity3D project or use Visual Studio to compile a DLL-file to be included in your project.
- Clone the repository
- Copy the files from
Assets\NeoNetwork
into your project- This folder also includes an Assembly definition file
- Clone the repository
- Open
NeoNetwork.sln
with Visual Studio - Build the solution using "Build -> Build NeoNetwork"
- Import the DLL (
obj/Release/NeoNetwork.dll
) into your Unity3D project
Hint: Unity currently always reset the LangVersion to "7.3" which isn't supported by Visual Studio. Therefor you need to manually
set / revert the LangVersion
to 6
in NeoNetwork.csproj
:
<LangVersion>6</LangVersion>
This library separates between the concept of a HTTP client and a HTTP request performer. The client acts as a facade to simplify the complexity of HTTP communication. The actual request performer must implement the IRequestPerformer
interface.
In the simplest usage one you simple instrument the provided UnityRequestPerformer
which uses the native Unity provided UnityEngine.UnityWebRequest
class.
var factory = new UnityRequestPerformerFactory();
var client = new Client(factory);
client.Get("http://www.neopoly.com", response => UnityEngine.Debug.Log(response.Body));
As the UnityEngine.UnityWebRequest
doesn't support the concept of cookies (outside of WebGL) the Client
will create an own ICookieJar
to support them. You can also use a shared
CookieJar if needed:
var factory = new UnityRequestPerformerFactory();
var cookies = new CookieJar();
var client1 = new Client(factory, cookies);
var client2 = new Client(factory, cookies);
// Getting a session via a cookie
var data = new Dictionary<string, string>(){
{"username", "foo"},
{"password", "boo"}
};
client1.Post("http://www.neopoly.com/login", data, response => UnityEngine.Debug.Log(response.Body));
// Use the same cookie for a second client
client2.Get("http://www.neopoly.com", response => UnityEngine.Debug.Log(response.Body));
- At the moment cookies are parsed from the response's header but don't respect the bounded domain. So they will be sent to any host.
- Due the decision from Unity to return the HTTP response headers as a
Dictionary<string, string>
only oneSet-Cookie
field can be respected per response.
Use Unity's embedded Test Runner via Window -> General -> Test Runner
.
- Support domain-based cookies
For the license of this project please have a look at LICENSE.txt