热门标签 | 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


推荐阅读
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 探讨如何高效使用FastJSON进行JSON数据解析,特别是从复杂嵌套结构中提取特定字段值的方法。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • Vue 2 中解决页面刷新和按钮跳转导致导航栏样式失效的问题
    本文介绍了如何通过配置路由的 meta 字段,确保 Vue 2 项目中的导航栏在页面刷新或内部按钮跳转时,始终保持正确的 active 样式。具体实现方法包括设置路由的 meta 属性,并在 HTML 模板中动态绑定类名。 ... [详细]
  • 本文探讨了如何通过最小生成树(MST)来计算严格次小生成树。在处理过程中,需特别注意所有边权重相等的情况,以避免错误。我们首先构建最小生成树,然后枚举每条非树边,检查其是否能形成更优的次小生成树。 ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • 程序员妻子吐槽:丈夫北漂8年终薪3万,存款情况令人意外
    一位程序员的妻子在网上分享了她丈夫在北京工作八年的经历,月薪仅3万元,存款情况却出乎意料。本文探讨了高学历人才在大城市的职场现状及生活压力。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 本文介绍了Java并发库中的阻塞队列(BlockingQueue)及其典型应用场景。通过具体实例,展示了如何利用LinkedBlockingQueue实现线程间高效、安全的数据传递,并结合线程池和原子类优化性能。 ... [详细]
  • 深入理解Java中的volatile、内存屏障与CPU指令
    本文详细探讨了Java中volatile关键字的作用机制,以及其与内存屏障和CPU指令之间的关系。通过具体示例和专业解析,帮助读者更好地理解多线程编程中的同步问题。 ... [详细]
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社区 版权所有