注意:已弃用 UNet,未来会将其从 Unity 中删除。一个新系统正在开发中。如需了解更多信息和后续步骤,请参阅此博客文章以及常见问题解答 (FAQ)。 |
NetworkServerSimple 是一个高级 API (HLAPI) 类,可管理来自多个客户端的连接。NetworkServer 类负责处理游戏类型内容(比如生成、本地客户端和玩家管理器)而且有一个静态接口,而 NetworkServerSimple 类是一个纯网络服务器,无任何游戏相关功能。NetworkServerSimple 也没有任何静态接口或单例,所以在同一时间内,在一个进程中可存在多个实例。
NetworkServer 类在内部使用 NetworkServerSimple 的实例来进行连接管理。
属性: | 功能: | |
---|---|---|
connections | 与远程客户端的活动连接的集合。这是一个稀疏数组,其中的 NetworkConnect 对象位于其 connectionId 的索引位置。对于最近关闭的连接,此数组中可能存在 null 值。位于索引零的连接可能是来自本地客户端的连接。 | |
handlers | 已注册消息处理程序函数的集合。 | |
networkConnectionClass | 要为新连接创建的 NetworkConnection 对象的类型。 | |
hostTopology | 此服务器用来配置传输层的主机拓扑对象。 | |
listenPort | 服务器执行监听的网络端口。 | |
serverHostId | 与此服务器实例相关联的传输层 hostId。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.