One server that acts as a middleman to connect a pair of clients or server and client for each pair

huangapple go评论70阅读模式
英文:

One server that acts as a middleman to connect a pair of clients or server and client for each pair

问题

  1. 第二种方法是否有特定的名称?

  2. 哪种方法更好?(考虑到没有太多的重型处理和目前不太担心可伸缩性)

我计划使用JavaScript和Node.js来实现这个,根据这一点,第一种方法似乎更加直接,但我不能仅凭这一点来证明。

英文:

I am developing a web application where two browsers will need to "connect" to each other in order to play a two-player game.

My initial thoughts on how to go ahead with this were to have one central server, which matches up a pair of clients and acts as a sort of "middleman". When browser A wants to make a move, it sends this to the server. The server then sends it to browser B. From my understanding, this is a typical client-server model.

However, an alternative approach would be to have one browser, e.g browser A that acts as both a server and a client and browser B will only act as a client. When browser A makes a move, it simply sends to brower B, (the client) and vice versa. Every time there is another pair of browsers that connect to play the game, one will act as a server and the other will be just a client.

I thought the second approach could be a peer-to-peer approach, however exactly half the clients will be strictly only be a client so I'm not sure if you can define it as a peer-to-peer model.

So my questions are:

  1. Is there a specific name for the second approach?

  2. What would be the better approach? (given that there isn't much heavy processing and I'm not too worried about scalability as of yet)

I am looking to implement this using javascript and node, and based on that it seems the first approach seems a bit more straightforward, however I cant really justify it apart from that

答案1

得分: 1

浏览器不能托管服务器。您需要拥有一个中央服务器,因为客户端无法相互连接,需要有人提供网页服务。有人需要进行端口转发,这是服务器的工作。

对于问题一,您提到的方法不存在。

对于问题二,最好的方法是让服务器管理一切。但是,您可以让服务器告诉一个客户端执行计算,然后简单地转发它们之间发送的数据包。没有最佳解决方案,这取决于您的服务器性能和游戏的需求有多高。

我建议对于像"四子连珠"这样的基本游戏,主服务器控制实际游戏,这也可以防止作弊。然而,像"谁是卧底"这样有很多活动的游戏将服务器在“主机”客户端和“客户”客户端之间转发数据。

英文:

Browsers cannot host servers. You need to have one central server, as clients cannot connect to each other, and someone needs to serve the webpage itself. Someone needs to port forward, that is the server's job.

For question one, your method doesn’t exist.

For question 2, the best approach is to have the server manage everything. However, you can have the server tell one client to do the calculations and simply forward the packets sent between them. There is no best solution, it depends on how powerful your server is and how demanding your game is.

I would recommend that for a basic game such as connect 4 you have the main server control the actual game, this also prevents cheating. However games like among us with a lot going on will have the server forward stuff between the "host" client and "client" client.

huangapple
  • 本文由 发表于 2023年2月9日 03:28:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390826.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定