位置: 编程技术 - 正文

High Level Networking Concepts

编辑:rootadmin

推荐整理分享High Level Networking Concepts,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

This section covers general networking concepts that should be understood before developing a game with Unity’s networking architecture.

What is Networking?

Networking is communication between two or more computers. A fundamental idea is that of the relationship between the client (the computer that is requesting information) and the server (the computer responding to the information request). The server can either be a dedicated host machine used by all clients, or simply a player machine running the game (client) but also acting as the server for other players. Once a server has been established and a client has connected to it, the two computers can exchange data as demanded by gameplay.

Creating a network game requires a lot of attention to some very specific details. Even though network actions are easy to design and create in Unity, networking remains rather complex. A major design decision in Unity is to make networking as robust and flexible as possible. This means that you, as the game creator, are responsible for things that might be handled in an automatic but less robust way in other engines. The choices you make potentially have a major effect on the design of your game, so it is best to make them as early in the design stage as possible. Understanding networking concepts will help you plan your game design well and avoid problems during the implementation.

Networking Approaches

There are two common and proven approaches to structuring a network game which are known as Authoritative Server and Non-Authoritative Server. Both approaches rely on a server connecting clients and passing information between them. Both also offer privacy for end users since clients never actually connect directly with each other or have their IP addresses revealed to other clients.

Authoritative Server

The authoritative server approach requires the server to perform all world simulation, application of game rules and processing of input from the player clients. Each client sends their input (in the form of keystrokes or requested actions) to the server and continuously receives the current state of the game from the server. The client never makes any changes to the game state itself. Instead, it tells the server what it wants to do, and the server then handles the request and replies to the client to explain what happened as a result.

Fundamentally, there is a layer of separation between what the player wants to do and what actually happens. This allows the server to listen to every client’s requests before deciding how to update the game state.

An advantage of this approach is that it makes cheating much harder for clients. For example, clients do not have the possibility of cheating by telling the server (and thereby other clients) that an enemy has been killed, since they don’t get to make that decision by themselves. They can only tell the server that a weapon was fired and from there, it is up to the server to determine whether or not a kill was made.

Another example of an authoritative server would be a multiplayer game that relies on physics. If each client is allowed to run its own physics simulation then small variations between clients could cause them to drift out of sync with each other gradually. However, if the simulation of all physics objects is handled on a central server then the updated state can be sent back to the clients, guaranteeing they are all consistent.

A potential disadvantage with authoritative servers is the time it takes for the messages to travel over the network. If the player presses a control to move forward and it takes a tenth of a second for the response to return from the server then the delay will be perceptible to the player. One solution to this is to use so-called client-side prediction. The essence of this technique is that the client is allowed to update its own local version of the game state but it must be able to receive corrections from the server’s authoritative version where necessary. Typically, this should only be used for simple game actions and not significant logical changes to game state. For example, it would be unwise to report to a player that an enemy has been killed only for the server to override this decision.

Since client-side prediction is an advanced subject, we don’t attempt to cover it in this guide but books and web resources are available if you want to investigate it further.

An authoritative server has a greater processing overhead than a non-authoritative one. When the server is not required to handle all changes to game state, a lot of this load can be distributed between the clients.

Non-Authoritative Server

A non-authoritative server does not control the outcome of every user input. The clients themselves process user input and game logic locally, then send the result of any determined actions to the server. The server then synchronizes all actions with the world state. This is easier to implement from a design perspective, as the server really just relays messages between the clients and does no extra processing beyond what the clients do.

There is no need for any kind of prediction methods as the clients handle all physics and events themselves and relay what happened to the server. They are the ownersof their objects and are the only agents permitted to send local modifications of those objects over the network.

Methods of Network CommunicationHigh Level Networking Concepts

Now that we’ve covered the basic architectures of networked games, we will explore the lower-levels of how clients and servers can talk to each other.

There are two relevant methods: Remote Procedure Calls and State Synchronization. It is not uncommon to use both methods at different points in any particular game.

Remote Procedure Calls

Remote Procedure Calls (RPCs) are used to invoke functions on other computers across the network, although the “network” can also mean the message channel between the client and server when they are both running on the same computer. Clients can send RPCs to the server, and the server can send RPCs to one or more clients. Most commonly, they are used for actions that happen infrequently. For example, if a client flips a switch to open a door, it can send an RPC to the server telling it that the door has been opened. The server can then send another RPC to all clients, invoking their local functions to open that same door. They are used for managing and executing individual events.

State Synchronization

State Synchronization is used to share data that is constantly changing. The best example of this would be a player’s position in an action game. The player is always moving, running around, jumping, etc. All the other players on the network, even the ones that are not controlling this player locally, need to know where he is and what he is doing. By constantly relaying data about this player’s position, the game can accurately represent that position to the other players.

This kind of data is regularly and frequently sent across the network. Since this data is time-sensitive, and it requires time to travel across the network from one machine to another, it is important to reduce the amount of data that is sent as far as possible. In simpler terms, state synchronization naturally requires a lot of bandwidth, so you should aim to use as little bandwidth as possible.

Connecting servers and clients together

Connecting servers and clients together can be a complex process. Machines can have private or public IP addresses and they can have local or external firewalls blocking access. Unity networking aims to handle as many situations as possible but there is no universal solution.

Private addresses are IP addresses which are not accessible directly from the internet (they are also called Network Address Translation or NAT addresses after the method used to implement them). Simply explained, the private address goes through a local router which translates the address into a public address. By doing this, many machines with private addresses can use a single public IP address to communicate with the internet. This is fine until someone elsewhere on the internet wants to initiate contact with one of the private addresses. The communication must happen via the public address of the router, which must then pass the message on to the private address. A technique called NAT punchthrough uses a shared server known as a facilitator to mediate communication in such a way that the private address can be reached from the public address. This works by having the private address first contact the facilitator, which “punches” a hole through the local router. The facilitator can now see the public IP address and port which the private address is using. Using this information, any machine on the internet can now connect directly with the otherwise unreachable private address. (Note that the details of NAT punchthrough are somewhat more complicated than this in practice.)

Public addresses are more straightforward. Here, the main issue is that connectivity can be blocked by an internal or external firewall (an internal firewall is one that runs locally on the computer it is protecting). For an internal firewall, the user can be asked to remove restrictions from a particular port so as to make the game server accessible. An external firewall, by contrast, is not under the control of the users. Unity can attempt to use NAT punchthrough to get access through an external firewall but this technique is not guaranteed to succeed. Our testing suggests that it generally works in practice but there doesn’t appear to be any formal research that confirms this finding.

The connectivity issues just mentioned affect servers and clients differently. Client requests involve only outgoing network traffic which is relatively straightforward. If the client has a public address then this almost always works since outgoing traffic is typically only blocked on corporate networks that impose severe access restrictions. If the client has a private address it can connect to all servers except servers with private addresses which cannot do NAT punchthrough (more will be said about this later). The server end is more complicated because the server needs to be able to accept incoming connections from unknown sources. With a public address, the server needs to have the game port open to the internet (ie, not blocked by a firewall). or else it cannot accept any connections from clients and is thus unusable. If the server has a private address it must be able to do NAT punchthrough to allow connections and clients must also permit NAT punchthrough in order to connect to it.

Unity provides tools to test all these different connectivity situations. When it is established that a connection can be made, there are two methods by which it can happen: direct connections (where a client needs to know the DNS name or IP address of the server) and connections via the Master Server. The Master Server allows servers to advertise their presence to clients which need not know anything about particular game servers beforehand.

Minimizing Network Bandwidth

When working with State Synchronization across multiple clients, you don’t necessarily need to synchronize every single detail in order to make objects appear synchronized. For example, when synchronizing a character avatar you only need to send its position and rotation between clients. Even though the character itself is much more complex and might contain a deep Transform hierarchy, data about the entire hierarchy does not need to be shared.

A lot of data in your game is effectively static, and clients need neither transfer it initially nor synchronize it. Using infrequent or one-time RPC calls should be sufficient to make a lot of your functionality work. Take advantage of the data you know will exist in every installation of your game and keep the client working by itself as much as possible. For example, you know that assets like textures and meshes exist on all installations and they usually don’t change, so they will never have to be synchronized. This is a simple example but it should get you thinking about what data is absolutely critical to share from one client to another. This is the only data that you should ever share.

It can be difficult to work out exactly what needs to be shared and what doesn’t, especially if you have never made a network game before. Bear in mind that you can use a single RPC call with a level name to make all clients load the entire specified level and add their own networked elements automatically. Structuring your game to make each client as self-sufficient as possible will result in reduced bandwidth.

Multiplayer Game Performance

The physical location and performance of the server itself can greatly affect the playability of a game running on it. Clients which are located a continent away from the server may experience a great deal of lag. This is a physical limitation of the internet and the only real solution is to arrange for the server to be as close as possible to the clients who will use it, or at least on the same continent.

Extra Resources

We’ve collected the following links to additional resources about networking:-

UnityException: Launching iOS project via Xcode4 failed 这是由于XCode版本较高,Unity还无法识别它的uuid。解决方法简单的可以更新Unity版本试试,另外的就是把XCode的DVTPlugInCompatibilityUUID添加到Unity中。Unityplist

Unity坐标转换问题 Unity中各种坐标系之间的转化一问题一世界坐标转NGUI坐标//worldPos是世界坐标系中一点Vector3pos=Camera.main.WorldToScreenPoint(worldPos);pos.z=0;//屏幕坐标z一直为0Vec

[Unity-] Prefab详解 1.什么是Prefab?Prefab又被称为预设,下面部分来自官网:预置是一种资源类型——存储在项目视图中的一种可重复使用的游戏对象。预置可以多次放入到

标签: High Level Networking Concepts

本文链接地址:https://www.jiuchutong.com/biancheng/384543.html 转载请保留说明!

上一篇:Animator窗口视图Project视图PlayerIdleAnimation和PlayerWalkingAnimation(animate怎么整个图层移动)

下一篇:UnityException: Launching iOS project via Xcode4 failed

  • 计提个人所得税会计分录怎么写
  • 赞助支出计入
  • 非货币性资产交换补价大于25%的会计处理
  • 非税收入票据可以手写吗
  • 计入税金及附加的税种口诀
  • 领备用金填什么单子
  • 购买车间使用的设备计入什么
  • 增值税零申报怎么报税
  • 法人把自己的车租给公司交什么税
  • 企业合并股份比例
  • 物业前期开办物资
  • 退休人员额外收入的税收标准
  • 现金抵用券购买怎么用
  • 税务机关退水利基金怎么做账?
  • 个人账户转公司账户需要交税吗
  • 工企业用地土地使用税怎么征收?
  • 行政单位的财务报告包括财务报表和财务情况说明书
  • 股票发行的会计分录
  • 增值税科目设置的凭证处理方面的特殊要求
  • 福利费抵扣了进项税有2年了怎么办
  • 清包工开票详细名称
  • 小规模建筑安装增值税税率是多少
  • 公司筹建期间的劳务费怎么入账
  • 离婚后房产过户需要多少钱
  • 平销返利税率
  • 工资税金算法
  • 公司食堂支出计入什么科目
  • 转让金融商品应交增值税怎么算
  • 施工组织评审会谁组织
  • win11任务栏白色卡死
  • 资产处置收益与固定资产清理
  • php处理ajax
  • 非盈利组织稳定吗
  • 跨年的定额发票可以用吗
  • shadowbar.exe - shadowbar是什么进程 有何作用
  • 什么叫非同一控制下
  • php单独运行
  • 进料加工贸易方式
  • 激光器原理及应用
  • css中设置字体样式
  • 前端技巧
  • ubuntu系统删除
  • 外贸企业上年的税收
  • 金融机构贷款准备金
  • 培训费用是什么成本
  • 一般纳税人购进小规模纳税人的货物
  • 管家婆实收资本显示负数什么原因
  • 为什么增值税发票不能折叠?
  • 其他收入工会经费是什么意思
  • 营改增后建筑企业财务核算
  • 企业设立账簿
  • 一般纳税人提供财政部和国家税务总局规定的
  • 关联方交易金额达到多少算转移定价
  • 货款发票如何入账
  • 试分析营改增的重大意义
  • 税控技术服务费怎么做账
  • 报表的应付账款怎么算
  • 固定资产出售增值税减按2%征收,附表一,填写
  • 商贸企业涉税问题
  • 投资性房地产收回自用
  • 企业注销前是不是资产必须处理完
  • win7系统如何恢复桌面图标
  • server2008 无法启动
  • 组装机没有装系统开机会怎么样
  • win10玩上古世纪闪退
  • Windows 8 Consumer Preview 中的新热键介绍
  • 简单谈谈对中国电信的认识
  • 如何用jquery
  • nodejs sleep方法
  • linux 监视器
  • 清除cookie是什么意思
  • vue中的计算属性forEach函数的使用
  • js中scrollHeight,scrollWidth,scrollLeft,scrolltop等差别介绍
  • gpu解码视频
  • js设置图片大小
  • 山东省关于退林还耕的规定
  • 哪些初级农产品可以免税
  • 工商与税务合并了吗
  • 到税务局领购免税产品
  • 增值税普通发票和电子普通发票的区别
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设