简体   繁体   English

Flash客户端和Java服务器之间的持久连接

[英]Persistent connections between Flash client and Java server

I'm new to Flash. 我是Flash的新手。 I'm planning to create a game client in Flash (running in browser) that needs to talk to a server written in Java. 我打算在Flash(在浏览器中运行)中创建一个游戏客户端,该客户端需要与用Java编写的服务器对话。 Connection between client and server needs to be persistent. 客户端和服务器之间的连接必须是持久的。

I'm aware of XMLSocket - is that the only way to go? 我知道XMLSocket-这是唯一的方法吗? Any recommendations? 有什么建议吗?

Thanks! 谢谢!

There's a Socket class, which lets you use real TCP when talking to a server. 有一个Socket类,可让您在与服务器通信时使用真实的TCP。 Downside - you'll have to implement the protocol yourself (that's implementing HTTP client in most cases. Maybe somebody already did it) 缺点-您必须自己实施协议(在大多数情况下,这是在实施HTTP客户端。也许有人已经做到了)

Are you just going to create the game for leaning and fun? 您是否只是要为娱乐而设计游戏? Otherwise I would recommend using an existing game server, or at least investigate the benefits and drawbacks of that option. 否则,我建议您使用现有的游戏服务器,或者至少研究该选项的优缺点。

I've used SmartfoxServer ( http://www.smartfoxserver.com ) in a couple of projects, it's not perfect but it takes a lot of your issues away (and you can write extensions in java if you want). 我在几个项目中使用过SmartfoxServer( http://www.smartfoxserver.com ),虽然它不是完美的,但是却带走了许多问题(如果需要,您可以使用Java编写扩展名)。 I do think ElectroServer http://www.electro-server.com/ is similar, and you can also have a look at the open source server Red5 http://osflash.org/red5 我确实认为ElectroServer http://www.electro-server.com/很相似,您也可以看看开源服务器Red5 http://osflash.org/red5

Besides sending stuff in xml you can also investigate if you can use AMF to send data, it might be smaller (as in less bits). 除了以xml格式发送内容外,您还可以调查是否可以使用AMF发送数据,它可能更小(以更少的位数表示)。

Make sure you have a security policy file available on the server. 确保服务器上有可用的安全策略文件。 Look at this SO question/answer for more info. 查看此SO 问题/答案以获取更多信息。

I've been experimenting with Socket communication between Flash and Java. 我一直在尝试Flash和Java之间的Socket通信。 One advantage of Socket over XMLSocket is bandwidth, because you can write binary data. 与XMLSocket相比,Socket的优势之一是带宽,因为您可以写入二进制数据。 So for example, you can send a single entity's position as: 因此,例如,您可以按以下方式发送单个实体的职位:

writeShort(entity.id); writeFloat(entity.x); writeFloat(entity.y);

Which is just 10 bytes. 仅10个字节。

Java supports similar primitive read/write functions with either DataStreams or ByteBuffers. Java通过DataStreams或ByteBuffer支持类似的原始读写功能。

Actually, the server side of things is more complicated than the Flash side, because you have to choose between the old io Java sockets and the new io methods. 实际上,服务器端要比Flash端复杂得多,因为您必须在旧的io Java套接字和新的io方法之间进行选择。 The new io methods have much better performance, but are more complicated and apparently filled with gotchas. 新的io方法具有更好的性能,但是更加复杂,并且显然充满了陷阱。

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

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