简体   繁体   English

对等与服务器客户端进行实时游戏

[英]peer to peer vs server client for real time game

I'm building a game that need real time sync between the users, currently I'm using tcp with no delay and its not fast enough. 我正在构建一个需要用户之间实时同步的游戏,目前我正在使用tcp且没有延迟,而且速度不够快。

the game supports 15 concurrent users, the server send the data to the users each 20 milliseconds if it have any thing to send, the data that being sent is max of 400 bytes for 1 user and the others send 30 bytes, the users send to the server their data every 50 milliseconds. 该游戏支持15个并发用户,如果有任何要发送的内容,服务器每20毫秒将数据发送给用户,一个用户发送的数据最大为400字节,其他用户发送的数据最大为30字节,每隔50毫秒向服务器发送一次数据。

while thinking about a solution i thought why not send the server each user connection data, he will send them back the "others" connection data and while the game running each user will send directly to all the other users his current information using udp . 在考虑解决方案时,我想为什么不将每个用户的连接数据发送给服务器,他将向他们发送“其他”连接数据,而运行每个用户的游戏将使用udp直接向所有其他用户发送其当前信息。

the second approach is keeping the current server client way and changing from tcp to udp 第二种方法是保持当前的服务器客户端方式,并从tcp更改为udp

what will be faster? 什么会更快? and will it make any difference from the current tcp client server speed? 它将与当前的tcp客户端服务器速度有所不同吗?

UDP will not necessarily be faster in a sense... though it will help speed things up. UDP在某种意义上不一定会更快……尽管它将帮助加快速度。 UDP doesn't consider whether the packet reaches the destination. UDP不会考虑数据包是否到达目的地。 Instead of waiting for the packet to reach the destination before sending more data, it will keep on sending as fast as possible. 在发送更多数据之前,它不必等待数据包到达目的地,而将继续保持尽可能快的发送速度。 If you want a real-time game that isn't turn-based, then you should try UDP. 如果您想要的不是基于回合制的实时游戏,则应尝试使用UDP。

This depends on the type of game. 这取决于游戏的类型。 Usually server client (with UDP) is used because the client is untrustworthy (can be modified to cheat.) 通常使用服务器客户端(带有UDP),因为客户端不可信(可以修改为作弊)。

UDP will only be faster if the client or servet has a bad internet connection that drops packets. 仅当客户端或服务器的互联网连接断开而丢包时,UDP才会更快。 This is because of the TCP retrying. 这是因为TCP重试。 Please note you will lose data. 请注意,您将丢失数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM