Warensoft Unity3D Communication Library Tutorial 2- Establish http communication via UnityHttpClient class

(Author: Warensoft, Email: warensoft@163.com)

Developers could send http requests, including GET request and POST request, by using Warensoft.Unity.Communication.Client.DataClient.UnityHttpClient class, and get the server response in a simple way. This class would be a total alternative to the WWW class.

The followings are the reasons why you need to use UnityHttpClient class

1> The naming styles of WWW class are not the Microsoft naming styles.

2> Concurrency problems. If developers send multiple http requests via WWW class, sometimes the mono runtime would throw a fatal exception (Too Many Threads), and then the whole application would crashes. But in UnityHttpClient, the requests are queued, and concurrency would be managed automatically.

3> The codes would be much more simple by using UnityHttpClient class

The followings are the usages of UnityHttpClient class:

1. Download the released binary files of Warensoft Unity3D Communication Lib

This class library is an open source project which is hosted in Codeplex, the address is : http://wucl.codeplex.com, just download the latest version. There are 2 DLLs,Warensoft.Unity.Communication.dll and Warensoft.DataService.dll, the first dll will be used in the following demo, and second dll is the warensoft data service library, we will describe it in the later chapters.

2. In order to implement this demo, we need to establish a website, and add 2 test files, one is a xml file(test.xml), and another one is a png image( test.png), as shown below:

clip_image001

The content of Test.xml is:

<?xml version="1.0" encoding="utf-8" ?>

 <Root>

      <Customer>ALFKI</Customer>

</Root>

7. Attach the cs script to the main camera in the scene, shown as below:

clip_image006

8. Save the project and run

the output scene in game view is shown as below:

clip_image007

the image below is the console output:

clip_image009

Last edited May 4, 2012 at 4:18 AM by warensoft, version 1

Comments

No comments yet.