简体   繁体   English

如何在Android中实现客户端服务器以制作BINGO游戏,而不是聊天应用程序

[英]How to implement client server in android for making BINGO game, but not for chat application

I am making a game of Bingo. 我正在玩宾果游戏。 For that I will be connecting two mobiles via wifi- hotspot and the grid should be shared to both clients, that is both mobiles should see the grid. 为此,我将通过wifi热点连接两个手机,并且网格应该共享给两个客户端,也就是说,两个手机都应该看到网格。 How can i pass the grid two both clients? 我怎样才能让两个客户同时通过网格? Also, how to pass numbers in between client and server? 另外,如何在客户端和服务器之间传递数字? Via object or other thing and how? 通过物体或其他东西,又如何? Also how to exactly implement client server application making 2 java files n android? 另外,如何正确实现制作2个Java文件和Android的客户端服务器应用程序? PS: we are not implementing a chat application. PS:我们没有实现聊天应用程序。

Bingo XML file: https://github.com/TanishaShrotriya/SDL/blob/master/activity_main_bingo.xml 宾果XML文件: https : //github.com/TanishaShrotriya/SDL/blob/master/activity_main_bingo.xml

Java File: https://github.com/TanishaShrotriya/SDL/blob/master/MainActivity_bingo.java Java文件: https//github.com/TanishaShrotriya/SDL/blob/master/MainActivity_bingo.java

You have a few options. 您有几种选择。 First you need to determine which architecture works for you. 首先,您需要确定哪种架构适合您。

Client/Server (AWS Instance with APIs, and Firebase with PUSH) ---This will enable the devices to get current came status on open, and push changes to their board on confirming their space was called/filled. 客户端/服务器(具有API的AWS实例,以及具有PUSH的Firebase)---这将使设备能够在打开时获取当前状态,并在确认已调用/填充空间的情况下将更改推送到其板上。 ---This will enable other devices in that "room" a name given to a virtual shared space for a game. ---这将为该“房间”中的其他设备启用游戏虚拟共享空间的名称。 To receive PUSH notification of changed data to display. 接收要显示的更改数据的PUSH通知。

Next you need to decide if the server will maintain the full state of each user or just the current called values for comparisons. 接下来,您需要确定服务器将保持每个用户的完整状态还是仅保持当前调用的值以进行比较。

If you decide that you do not want to write APIs and setup a Server for PUSH, you can do an ad-hoc wi-fi or even a BLE based communication among everyone in the area. 如果您决定不想编写API并为PUSH设置服务器,则可以在该区域的每个人之间进行即席wi-fi或基于BLE的通信。 However, this will require significantly more understanding of how to pass bytes, handle network issues, latencies, and communicating from device to device. 但是,这将需要对如何传递字节,处理网络问题,延迟以及如何在设备之间进行通信有更多的了解。

If you choose to do the ad-hoc wifi as you mentioned you would have to maintain a ton of connections like a mesh network. 如果您选择按照您提到的方式进行临时wifi,则必须维护大量连接,例如网状网络。 A better option would be to have all devices join the same wifi network so that they have access to each other, but aren't necessarily keeping track of mesh networking. 更好的选择是让所有设备都加入同一个wifi网络,以便它们可以相互访问,但不必跟踪网状网络。

However, even if you are on the same wifi knowing who to send the information to can be difficult without a server to retain routes and IPs of current players. 但是,即使您在同一个wifi上,如果没有服务器保留当前播放器的路由和IP,也很难知道将信息发送给谁。 So you may have to create a host so that it can listen for enrolled players. 因此,您可能必须创建一个主机,以便它可以侦听已注册的玩家。 The host device would need to retain routes to all other devices so that it can send the info to each IP address when a change occurs. 主机设备将需要保留到所有其他设备的路由,以便在发生更改时可以将信息发送到每个IP地址。

I still highly recommend going the client/server route of APIs and PUSH it will be far more reliable. 我仍然强烈建议您使用API​​和PUSH的客户端/服务器路由,它将更加可靠。

Now as far as how to pass the data, you could of course screenshot via code and send images, but that is wasteful. 现在,关于如何传递数据,您当然可以通过代码截屏并发送图像,但这很浪费。 I would recommend having a matrix that keeps track of the values covered and simply send a JSON snippet of the card_id, the player_id, and the json of covered blocks to the server that can then push changes back to all players in the "virtual room". 我建议您使用一个矩阵来跟踪覆盖的值,并简单地将card_id,player_id和Covered块的JSON片段发送至服务器,然后再将更改推回“虚拟房间”中的所有玩家。 This allows them to see how their fellow competitors are doing. 这使他们可以看到竞争对手的表现。

So I would have to ask for more details about what your goal is to help any further, but that is my recommendation, because ad-hoc wifi or bluetooth is doable, but on a mesh scale size you will have a giant headache on your hands. 因此,我将需要询问有关您的目标进一步帮助的更多详细信息,但这是我的建议,因为可以使用即席wifi或蓝牙,但在网目尺寸的情况下,您会头疼不已。 The host scenario device with all on same wifi would be my second direction if you are really anti-server and APIs, which the only reason I could see you avoiding that is if you wanted to play off wifi that doesn't have internet or if you don't want to pay the $30/month for traffic while it is small. 如果您确实是反服务器和API,那么主机场景设备全部位于同一wifi上将是我的第二个方向,这是我能避免看到的唯一原因,如果您想使用没有互联网的wifi或您不想在流量很小的情况下每月支付$ 30的流量。

Let me know if that helps or if you want to provide additional clarity. 让我知道这是否有帮助,或者您是否想提供其他说明。

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

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