热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

U3D网络库实现通信基于WarensoftUnity3d

WarensoftUnity3dCommunicationLibthisisahighperformancecommunicationlibraryfor Unity3d,incl

Warensoft Unity3d Communication Lib

this is a high performance communication library for Unity3d,including some easy-to-use httpclasses,andsocket classes. And especially,it brings a totally new method to access to MS SQL SERVER2005+via http protocol.

该类库是专门为Unity3D编写的一个高性能通信库,其中包括了若干十分易于使用的Http通信类以及Socket通信类.另外最特别之处在于,它引入了一全新的,基于Http协议的数据库访问组件,可以轻松访问MS SQL SERVER2005+.

Features

1. Microsoft C# naming standards

    微软命名规范

As a C# developer, you will find the that the unity3d naming standard is quite different, and not comfortable. But in this lib, everything (fields, properties, methods, events) you see will goes with Microsoft naming standards.

作为一个C#开发人员,您会发现Unity3d中的命名规范与其他的C#例程中的命名规范大不相同,如字段公有化等.但是在该类库中,所有能够看到的内容(包括字段,属性,方法,事件)全部符合微软命名规范.

2. Communication via Http protocol

    基于HTTP协议的通信

Every class which could be used to process http request and response in .net framework ,such as WebRequest, WebClient, will not work in unity3d, instead of them, the only class you can use is the WWW class. For the beginners, the usage of WWW class may seems strange(yeah, in a 3d engine, you need to do in that way), actually, it is totally different from the Microsoft way. And the most painful points are the memory leak when dispose the http resources, and  the multithreading concurrency problem(if you create a lot of instance of WWW class at the same time ,then some times the engine will throw an exception:Too Many Threads, and then the application crashes).

Unity3D,开发人员只能使用WWW类来处理Http的请求和响应,原有的在DotNet Framework中的WebRequest类和WebClient,Unity3D中是无法使用的.对于初学者来讲,WWW类的使用方法有点奇怪(当然,3D引擎中,你必须这样做), 事实上,WWW类的使用方式与微软的编程风格完全不同当然,最令人头疼的是当你释放WWW类所占用的内存资源时,会出现较为明显的内存泄漏另外,过多使用WWW类会产生多线程并发问题,当开发人员同时建立多个WWW类的实例来并发访问多个Web资源时,经常会出现Too Many Threads(线程太多)的异常,然后整个系统就崩溃了.

In Warensoft Unity Communication Lib, a totally new class UnityHttpClient will be the best alternative. the HttpClient class simplifies the process of getting response, and it controls the concurrency numbers automatically in the background. Just compare the two types of codes, the 1st type is implemented with WWW class ,and the 2nd type is implemented with HttpClient class:

Warensoft Unity3D通信库为您引入了一个全新代替方案:UnityHttpClient.使用UnityHttpClient类发送Http请求以及获取响应将变的极为简单,另外,该类在自动在后台控制并发的线程数量.请对比以下两段代码,第一段是使用WWW类实现的,第二段代码是使用UnityHttpClient类来实现的.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///With WWW Class

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class WWWTest:MonoBehaviour

{

    WWW www;

    void Start()

    {}

    private int initStep=0;

    void Update()

    {

        switch (this.initStep) {

        case 0:

            this.www=new WWW ("http://www.abc.com/default.aspx");

            this.initStep=1;

            break;

        case 1:

            if (this.WWW.isDone)//waite until the http response is finished

            {

                print(this.www.text);

            }

            break;

        default:

        break;

        }

    }

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//With HttpClient class

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class HttpClientTest:MonoBehaviour

{

    UnityHttpClient client;

    void Start(){}

    private int initStep=0;

    void Update()

    {

if(this.initStep==0)

{

        //create an instance

         this.client=UnityCommunicationManager.CreateInstance().GetHttpClient();

        this.client.BeginGetHttpContent("http://www.abc.com/default.aspx",new Action<string>((result)=>

        {

            print(result);

        }));

        this.initStep=1;

         }

    }

}

//end of the test

As the code you see,it is not difficult to find that HOW EASY the usage of UnityHttpClient is!

正像你看到的一个,使用HttpClient类是如此的简单!

3. Communication via Tcp protocol

    基于TCP协议的通信

In most cases,http protocol would be your choice,but sometimes,you will need something faster, and real time push from the server to every client without client polling(duplex communication), for example,there are a lot of characters walking in the same scene, but they are not npcs,that means every character is controlled by someone in front of a client computer,so,you need a fast way to synchronize the positions of these person models.

使用Http方式进行远程通信,固然可以解决绝大多数问题,但是有些时候你可能需要更快的通信,并且需要服务器可以将实时数据直接推送到客户端(不需要客户端定时查询).例如,在同一个场景中可能有很多人物在走动,这些人物不是NPC,而且它们都是由计算机前面的人来控制的.因此,你需要一个更快速的方法去同步这些人模的坐标信息.

The most efficient way is to build a series of custom protocols which are based on Tcp protocol. But unfortunately,Unity3d dose not provide too much easy-to-read documents about the network view component. Or instead of network view component, you could choose the Socket class of .net framework,it will solve any problem of network communication, but it is also the lowest API,and hard to control.

最有效的解决方法就是基于TCP协议之上制定一系列的自定义协议.但不幸的是,关于Unity3D内置的network view组件,官方并没有提供太多的,易于阅读和理解的文档.或者,你可以使用.NET Framework中的Socket类取而代之.Socket类可以说是一个万能的通信类,没有它搞不定的,但同时Socket类也是最低层的一个类,并且十分难以控制.

Warensoft Unity Communication Lib brings an alternative,The SocketClient class, an easy-to-use and easy-to-control class

Warensoft Unity 通信库引入了一个用于替代的SocketClient,一个使用简单,控制极为容易的类.

4. Accessing to MS SQL SERVER2005 with Warensoft Data Server

通过Warensoft数据访问服务访问MS SQL SERVER2005+数据库

For security reasons,the unity3d web player could not access to MS SQL SERVER(ADO.NET is unavailable). According to the common security policy of RIA technologies(such as silverlight,flash,js),RIA clients doesn‘t have the right to access to databases. Under the web player circumstance,the best practice is Proxy Pattern or just expose a simple web service API (HTTP service, HTTP soap web service,ext) on the server.

出于安全角度考虑,Unity3DWebPlayer,是不可以访问MS SQL SERVER(ADO.NET不可用).SilverlightFlash一样,通常情况下富客户端应用一般都是不能访问数据库的(这是一点是默认的安全策略).WebPlayer的环境下,最佳的实践方式就是使用代理模式(Proxy Pattern),或者干脆就在Web服务器上提供一个简单的Web服务接口(可以基于HTTP方式的服务,也可以是一个SOAPWeb服务等).

So,in Warensoft Unity3d Communication Lib, we provide a set of client proxy classes for Warensoft data service. Just few steps, you will be able to access to a MS SQL SERVER database.

为此,我们为您提供了一个名为Warensoft数据服务的代理数据访问技术,并且在Warensoft Unity 通信库中提供了一组客户端代理类,仅仅需要几步,您就可以轻松的实现SQL SERVER数据库访问

U3D 网络库实现通信 基于Warensoft Unity3d


推荐阅读
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • WebShell代码分析溯源(二)
    WebShell代码分析溯源(二)一、一句话变形马样本 ... [详细]
  • 去网上在线生成一个favicon.ico图标,然后把下面的代码复制到页面的head ... [详细]
  • 关于linux下,ls vi等命令失效的解决方法(配置下环境变量出现问题)
    配置完环境变量source之后,linux的lsvi命令均失效,报错如下:解决方法1.输入 exportPATHusrbin:usrsbin:bin:sbin:usrX11R6bi ... [详细]
  • 将android-support-multidex.jar放到libs下然后编译,出现如下错误:Error:Executionfailedfortask':app:pack ... [详细]
  • 本文内容为asp.net微信公众平台开发的目录汇总,包括数据库设计、多层架构框架搭建和入口实现、微信消息封装及反射赋值、关注事件、用户记录、回复文本消息、图文消息、服务搭建(接入)、自定义菜单等。同时提供了示例代码和相关的后台管理功能。内容涵盖了多个方面,适合综合运用。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
author-avatar
传闻中的张先生
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有