Persistent connections between Flash client and Java server

不打扰是莪最后的温柔 提交于 2019-12-21 23:44:58

问题


I'm new to Flash. I'm planning to create a game client in Flash (running in browser) that needs to talk to a server written in Java. Connection between client and server needs to be persistent.

I'm aware of XMLSocket - is that the only way to go? Any recommendations?

Thanks!


回答1:


There's a Socket class, which lets you use real TCP when talking to a server. Downside - you'll have to implement the protocol yourself (that's implementing HTTP client in most cases. Maybe somebody already did it)




回答2:


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). 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

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).




回答3:


Make sure you have a security policy file available on the server. Look at this SO question/answer for more info.




回答4:


I've been experimenting with Socket communication between Flash and Java. One advantage of Socket over XMLSocket is bandwidth, because you can write binary data. 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.

Java supports similar primitive read/write functions with either DataStreams or ByteBuffers.

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. The new io methods have much better performance, but are more complicated and apparently filled with gotchas.



来源:https://stackoverflow.com/questions/1300755/persistent-connections-between-flash-client-and-java-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!