kryonet

如何用Nearby Service让你的游戏实现近距离联机

六眼飞鱼酱① 提交于 2020-08-07 20:56:17
  复杂的自组网,偶发的长尾时延,无法连接网络的场景,这些问题是否制约你的游戏盈利? HMS Nearby Service(近距离通信服务)提供了便捷的近距离P2P直连通信,可为你的游戏带来:   Nearby Service在游戏场景下具有如下技术优势: 综合使用蓝牙、Wi-Fi进行节点发现。你的游戏集成之后,可以自动搜索附近打开游戏的用户,无需用户手动打开热点进行连接。 自动选择最优的组网和传输方式。支持点对点、星型、网状多种拓扑,支持Wi-Fi P2P,无需连接到同一个AP。 使用华为自研传输协议,高带宽,低延时,稳定可靠。 应用开发   我们在GitHub上找到一款名为《Snake Land》的开源贪食蛇游戏, 以此款游戏为例子,集成Nearby Service作为游戏的网络通信管道,实现联机对战功能。《Snake Land》原先使用开源框架Kryonet实现网络通信层。Kryonet只支持连接同一路由器的手机设备之间互联。集成Nearby Service后,手机连接不同Wi-Fi、不连接Wi-Fi、或者在没有网络等场景下,都可以与附近的手机联机,实现真正的“靠近即连”。 开发准备   集成Nearby Service之前,需要完成以下准备工作 配置AppGallery Connect 开通近距离通信服务 集成SDK 配置混淆脚本   详细信息请参考 开发准备 。

Multidimensional array with unknown size

最后都变了- 提交于 2019-12-23 04:33:38
问题 I need to create an array with an undefined size, which will contain user information. For example: user[0]["name"] = "Patrick"; However, the standard java array seems to require a known length, which I don't know. What alternative can i use? (I'll gladly see some coding examples as well) I'm using a TCP framework (kryonet) which doesn't allow to pass objects with constructors. Therefore, as far as i can see, making a User object is not possible. 回答1: In java we can only use integer values

P2P message sending using NAT punch-through in Android

心不动则不痛 提交于 2019-12-22 09:47:41
问题 I try to send a message from one phone to another using Kryonet (that uses socket communication) and I intend to use NAT punch-through by storing the public address of the clients. The following code is used: public class MainActivity extends Activity implements View.OnClickListener { /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = ((Button)

Kryonet packet not sent

爱⌒轻易说出口 提交于 2019-12-17 16:54:15
问题 So I'm trying out kryonet, sending a custom packet, but the listener in my server can't seem to pick it up. server.addListener(new Listener() { @SuppressWarnings("unused") public void received(Connection connection, Object object) { System.out.println("received"); if (object instanceof Packet) { Packet p = (Packet) object; System.out.println(p.name); } } }); Sending: Packet p = new Packet(); p.name = "test"; client.sendTCP(p); Reading through other threads, I've tried using new Thread(client)

Kryonet packet not sent

為{幸葍}努か 提交于 2019-12-17 16:54:04
问题 So I'm trying out kryonet, sending a custom packet, but the listener in my server can't seem to pick it up. server.addListener(new Listener() { @SuppressWarnings("unused") public void received(Connection connection, Object object) { System.out.println("received"); if (object instanceof Packet) { Packet p = (Packet) object; System.out.println(p.name); } } }); Sending: Packet p = new Packet(); p.name = "test"; client.sendTCP(p); Reading through other threads, I've tried using new Thread(client)

How to send objects over a network using Kryonet?

蹲街弑〆低调 提交于 2019-12-13 14:19:50
问题 I am new to networking, and I am trying to network a board game that I have created using java.A friend of mine pointed me towards the Kryonet library. So far, it's great. I don't have to deal with sockets! The problem I'm coming across is sending objects. Mainly, I have a Board type object. This object contains other objects, such as ArrayList objects and Fort objects. I tried just registering the Board object, but I received these errors: Exception in thread "Server" com.esotericsoftware

Kryonet client disconnects after send a packet to server (java)

主宰稳场 提交于 2019-12-11 18:03:05
问题 I'm doing a little MMO project and right now I'm working on the login/register system. Whenever I try to send a ClientLoginPacket, the client disconnects from the server and the packet is not received at all by the server. There is no stack trace that shows up but here is my code. Sorry it's a lot but it's all necessary: ClientLoginPacket.java: package net.vediogames.archipelo.networking.packets; import net.vediogames.archipelo.networking.Networking; public class ClientLoginPacket extends

Boolean not changing in thread

試著忘記壹切 提交于 2019-12-02 15:44:59
问题 I have a class MPClient and MultiplayerMatch. MultiplayerMatch, in his constructor, creates a MPClient runnable thread. To avoid data overflow, I have a boolean named "moved" in MultiplayerMatch that changes to true when the player is moving. In the updateMatch method, if there's any player movement, "moved" changes to true, which allow MPClient to enter an if statment (inside while). This way MPClient only sends data to the server when something changes on the game. Neverthless, when the

Boolean not changing in thread

本秂侑毒 提交于 2019-12-02 03:43:49
I have a class MPClient and MultiplayerMatch. MultiplayerMatch, in his constructor, creates a MPClient runnable thread. To avoid data overflow, I have a boolean named "moved" in MultiplayerMatch that changes to true when the player is moving. In the updateMatch method, if there's any player movement, "moved" changes to true, which allow MPClient to enter an if statment (inside while). This way MPClient only sends data to the server when something changes on the game. Neverthless, when the flag is true, in MPClient that change is not registed! MPClient still "thinks" moved equals false, even

Kryonet packet not sent

你说的曾经没有我的故事 提交于 2019-11-28 01:42:39
So I'm trying out kryonet, sending a custom packet, but the listener in my server can't seem to pick it up. server.addListener(new Listener() { @SuppressWarnings("unused") public void received(Connection connection, Object object) { System.out.println("received"); if (object instanceof Packet) { Packet p = (Packet) object; System.out.println(p.name); } } }); Sending: Packet p = new Packet(); p.name = "test"; client.sendTCP(p); Reading through other threads, I've tried using new Thread(client).start(); instead of client.start(); , and I've added empty constructors to my packet classes, but the