简体   繁体   English

具有客户端服务器模型的井字游戏

[英]Tic-Tac-Toe-Game With Client Server Model

I have a little problem in the application I should write.我在应该编写的应用程序中遇到了一个小问题。 I have to write a simple Tic-Tac-Toe game with the client server model using UNIX domain sockets.我必须使用 UNIX 域套接字使用客户端服务器模型编写一个简单的井字游戏。 I thought that it would be a good solution if I had one client per player (total of two players) but now I have a problem in synchronizing them.我认为如果我每个玩家有一个客户端(总共两个玩家)会是一个很好的解决方案,但现在我在同步它们时遇到了问题。 How can the server distinguish between the first and the second client when keeping track of the moves of the players?服务器在跟踪玩家的移动时如何区分第一和第二客户端? More specific: How can I synchronize the two clients in such a way that the first one connected to the server will take the first move, then the second one, the first one again and so on?更具体地说:如何同步两个客户端,使连接到服务器的第一个客户端先行,然后是第二个,第一个又是第一个,依此类推? I didn't use a multithreaded server because I only have two players.我没有使用多线程服务器,因为我只有两个玩家。

I would appreciate any help and suggestions!我将不胜感激任何帮助和建议!

The quadruplet (SrcIP, SrcPort, DstIP, DstPort) is a unique identifier for each connection.四元组(SrcIP, SrcPort, DstIP, DstPort)是每个连接的唯一标识符。 Map it into some playerId .将其映射到某个playerId use that Id whenever you encounter a received packet.每当您遇到收到的数据包时,请使用该 ID。

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

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