编辑“︁
NetworkDesign
”︁(章节)
跳转到导航
跳转到搜索
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
==网络管理器== The Network Manager is our router that sends and receives messages to and from the network. The manager exposes the interfaces that allow: * Reading a message from the network * Sending a message to the network * Finalizing the manager The read operation is a blocking type operation so we have two options, either polling (i.e. continually checking if data is there) or blocking (i.e. only processing when data is actually available, otherwise sleeping). We choose blocking because we don't want to waste CPU time polling the network for messages, we just want to sleep until messages are available. Hence we create a Thread to read from the Network, let's call it NetworkManagerRead. 将消息写入网络可以简单地编码为网络管理器的一种方法,因为写入是一种本质上不会阻塞的操作. NetworkManager将打开一个套接字,它将从中接收来自网络的所有消息。 它还将从同一套接字将所有出站消息写入网络。 注意:写入和读取都使用相同的套接字. 为了封装所有这些内容,我们将Read和Write方法都创建为Network Manager的内部类。. <pre> NetworkManager { socket messages pendingToSendMessages NetworkManagerRead isa Thread { read socket build message store in messages } NetworkManagerWrite isa Thread { get from pendingToSendMessages serialize message send socket } } </pre> 如您所见,收到消息后,消息将存储在列表中。 因此,对列表的访问必须同步. 现在,让我们回到暴露给其他对象的界面。 write方法是即时的,只需在发送消息时调用它即可,并确保已正确填写SourceAddress和ClientID。 然后,该消息将发送给客户端. read方法处于阻塞状态,当您调用read方法时,它要么从队列中返回一条消息,要么如果队列为空,则线程阻塞(休眠)直到一个到达. 这是网络管理器的基本思想。 请注意,管理器仅发送一次数据包流,并且不确认是否接收到任何消息。 TCP负责确认. [[Category:Marauroa]] {{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Developers|Internals]] | [[NetworkDesign|Network Design]] }}
摘要:
请注意,所有对gamedev的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Gamedev:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
页面
讨论
不转换
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息