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


推荐阅读
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • 本文介绍如何通过Windows批处理脚本定期检查并重启Java应用程序,确保其持续稳定运行。脚本每30分钟检查一次,并在需要时重启Java程序。同时,它会将任务结果发送到Redis。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细探讨了Java中的24种设计模式及其应用,并介绍了七大面向对象设计原则。通过创建型、结构型和行为型模式的分类,帮助开发者更好地理解和应用这些模式,提升代码质量和可维护性。 ... [详细]
  • 本文基于刘洪波老师的《英文词根词缀精讲》,深入探讨了多个重要词根词缀的起源及其相关词汇,帮助读者更好地理解和记忆英语单词。 ... [详细]
  • 数据管理权威指南:《DAMA-DMBOK2 数据管理知识体系》
    本书提供了全面的数据管理职能、术语和最佳实践方法的标准行业解释,构建了数据管理的总体框架,为数据管理的发展奠定了坚实的理论基础。适合各类数据管理专业人士和相关领域的从业人员。 ... [详细]
  • CentOS7源码编译安装MySQL5.6
    2019独角兽企业重金招聘Python工程师标准一、先在cmake官网下个最新的cmake源码包cmake官网:https:www.cmake.org如此时最新 ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • MySQL中枚举类型的所有可能值获取方法
    本文介绍了一种在MySQL数据库中查询枚举(ENUM)类型字段所有可能取值的方法,帮助开发者更好地理解和利用这一数据类型。 ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
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社区 版权所有