查看: 2203|回复: 2

[教程] unity3d原创译文网络传输层的普及性介绍(下)

[复制链接]

6

主题

1

听众

148

积分

设计实习生

Rank: 2

纳金币
169
精华
0

最佳新人

发表于 2014-8-8 12:39:12 |显示全部楼层
All about the unity networking transport layer
Unity网络传输层的那些事
小编的话:来自Unity官网(6月11日)的文章,本文称得上是可以给大家做普及的技术类文章,有些可能基础,但确实需要掌握哩。
我罗列下关键词,方便大家阅读:QOS、UNET、信道、传送、连接、断开、请求。
(上)篇的链接   http://www.unitymanual.com/thread-20724-1-1.html

UNET (so far) supports the following QOS:
截至目前,UNET(网络技术)支持以下的QOS(服务质量):

•        Unreliable: An unreliable message which can be dropped due to network conditions, or internal buffers overflow, similar to UDP packet.  Example: Short Log Messages.
•        不可靠信息:依据网络状况的不同,或者是内部缓冲区溢出,而能被丢弃的不可靠信息,跟UDP包的情况很相似。 例如:短日志信息。
•        UnreliableFragmented: Maximum packet length is fixed, but sometimes you will probably want to send “big” messages. This channel type will disassemble your message to fragments before sending, and assemble it back before receiving. As this qos is unreliable, delivery is not granted.  Example: Long  Logs
•        不可靠片段化:虽然包的最大长度是固定的,但有时你可能想发送一些“大”消息。这个信道会把你的消息,在发送之前,先分成多个片段,然后再在接收之前重新整合起来。正如上文说的,这个QOS是不可靠的,就不能保证传送成功。 例如:长日志

•        UnreliableSequenced: Channel grants delivery order, as this qos is unreliable, the message can be missed. Example: voice, video
•        不可靠序列化:信道保证传送顺序,但是因为这个QOS是不可靠的,这个消息有可能会被漏掉。 例如:声音,视频

•        Reliable: Channel grants delivery (or disconnect) but not grant order.  Example: Sending Damage
•        可靠信息:信道保证传送(或者断开连接),但是不保证顺序。 例如:传输中断

•        ReliableFragmented: Same as UnreliableFragmented, but additionally it will grant delivery.  Example: Group Damage
•        可靠片段化:和不可靠片段化相似,但是可靠片段化会保证传输成功  例如:群组中断

•        ReliableSequenced: Same as UnreliableSequenced, but additionally it will grant delivery. This QOS is analogous to TCP stream.  Example: File Delivery/Patching
•        可靠序列化:和不可靠序列化相似,但是可靠序列化会保证传输成功。这个QOS与TCP流很类似。 例如:文件传送/补丁

•        StateUpdate: An unreliable channel type plus channel with this qos will force drop messages which are older than sending/receiving. If when sent, send buffer contains more than one message, only the youngest will send. If the receiving buffer, when reading, contains more than one message only the youngest will be delivered.  Example: Sending Position
•        状态更新:不可靠类型的信道以及使用此QOS的信道,会强制丢弃那些比发送/接收还要早的消息。如果是要发送,而且发送缓冲区中的消息不止一条时,那么只有最新的那一条消息会被发送。如果接收缓冲区,当读到多于一条的消息时,那么只有最新的消息会被传送。 例如:发送位置

•        AllCostDelivery: Fairly similar to Reliable qos, but there is a difference. The reliable channel will resend undelivered messages based on round trip time value (RTT) which is a dynamic parameter while AllCostDelivery will automatically resend messages after a period of time (configured value). This can be useful for small important messages: “I shot player A in the head” or “Mini-game starts”.  Example: Game events such as firing bullets
•         不惜一切代价传送:与可靠QOS极其相似,但也有差异。可靠信道将重新发送,基于一个动态参数的往返时间(简称为RTT,指某些数据在网络上的延迟时间)。在一段时期过后(配置值出来后),“不惜一切代价传送”将自动地重新发送信息。这对于一些小且重要的消息很有用:“我射中了玩家A的头”或者“迷你游戏开始”。例如:像发射子弹的游戏事件

        If you have a use case you feel doesn’t fit conveniently in these categories, we’d love it if you could bring it up in the comments!
        如果你发现个使用案例,但不怎么适合这种分类方式时,我们很欢迎你能够在评论中提出来!

Let’s review typical LLAPI function calls:
让我们来回顾一下LLAPI的一些经典方法调用吧:


1.         Initialize library
1.         初始化库:
2.         Configure network: topology, channels amount, their types, different timeouts and buffer sizes (we discuss this in a later post)
2.         网络配置:拓扑结构,信道数量,它们的类型,不同的超时,以及缓冲区大小(这些我们会在后续的帖子中进行详细阐述)。

3.         Create socket:
3.         创建Socket:
        This function will open the socket on port 5000 on all network interfaces, and will return an integer value as a descriptor of this socket。
         这个方法会打开所有网络接口中,端口5000的Socket。同时会返回一个整数值作为Socket的描述符号。


4.         Make connection to other peer:
4.         和另一个对等点连接:

        This function will send a connection request to “other peer” at address 127.0.0.1/6000. It will return an integer value as a descriptor of this connection for this host. You will receive the connection event when the connection is established or the disconnect event if the connection cannot be established.
       这个方法会将一个连接请求发送给地址为127.0.0.1/6000的“另一个对等点”。它会为这台主机返回一个整数值,作为连接的描述符号。当建立起连接时,你会接收到一个连接事件;连接未能建立起来时,你会接收到一个断开事件。

5.           Send message:
5.           发送消息


      This last function will send binary data contained in the buffer via socket described by hostId for peer-described connectionId using channel #1 (in our case this is “reliable channel”, so for this message delivery will be granted.
      最后一个方法,会通过用hostId标记的Socket,将缓冲区中包含的二进制数据,发送给用对等点描述的connectionId。在实例当中,我们用的是信道1,而信道1是“可靠信道”,因此我们可以保证这个消息能成功传送。

6.           Receiving network events:
6.           接收网络事件
           For receiving network events, we chose a poll model. User should poll UTransport.Receive()function to be acknowledged about network events. Note that this model is very similar to ordinary select() call with zero timeout. This function receives 4 different events:
           为了接收网络事件,我们选择了一个检测模型。用户应该通过检查UTransport.Receive()方法来获取网络事件的信息。需要注意的是,这个模型与普通的select()方法的调用非常相似,即超时为零。该方法会接收四种不同事件:
•        UNETEventType.kConnectEvent - somebody connects to you, or connection requested by  UTransport.Connect() call has been successfully established
•        UNETEventType.kConnectEvent -有人与你建立了连接,或者调用UTransport.Connect()方法请求成功建立一个连接
•        UNETEventType.kDisconnectEvent - somebody disconnects with you, or connection requested by UTransport.Connect() call cannot be established for some reason (error code will report what this reason was)
•        UNETEventType.kDisconnectEvent – 有人与你断开了连接,或者调用UTransport.Connect()方法请求建立一个连接,因某些原因,不能被创建(错误代码会报出到底是什么原因)
•        UNETEventType.kDatatEvent  - New data has been received
•        UNETEventType.kDatatEvent – 接收到了新的数据
•        UNETEventType.kNothing - Nothing interesting happened
•        UNETEventType.kNothing – 没有什么事件发生

7.       Send disconnect request:
7.       发送断开请求:
       This function call will send a disconnect request to a connection defined by connectionId on host defined by hostId. The connection will close immediately and can be re-used in the future.
       这个功能调用,会向一台通过hostId定义的主机,发出一个由connectionId定义的连接的断开请求。这个连接会马上中断,但是它在之后,还能够重新使用。

       That’s it for now! Thanks for reading, and don’t forget to check back (or subscribe to our blog) to catch the next post in the UNET series in which we’ll be discussing network topology configuration.
       先说这么多吧!感谢大家花时间阅读我们的帖子,不要忘记常回来看看(或者订阅我们的博客)。这样就不会错过,我们之后发布的有关UNET系列的帖子。下一次,我们会讨论一些有关网络拓扑的配置问题。

      (上)篇的链接   http://www.unitymanual.com/thread-20724-1-1.html
       我是游戏蛮牛的蛮牛译馆(一个专门翻译国外资料的组织)的一员,我会陆续整理,翻译国外unity相关的新闻资讯与技术文章,以及各种视频等内容。我们也欢迎热爱游戏翻译的好友加群,一起体验翻译并分享乐趣,QQ群号:52677537。关于此篇文章翻译有错误的地方,欢迎大家指正。
回复

使用道具 举报

2317

主题

54

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
20645
精华
62

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2014-8-8 13:25:18 |显示全部楼层
这个是广告贴吗..?
回复

使用道具 举报

0

主题

2

听众

4092

积分

中级设计师

Rank: 5Rank: 5

纳金币
530
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2014-8-9 07:28:01 |显示全部楼层
Thanks for sharing
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-3-29 13:52 , Processed in 0.095470 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部