views:

709

answers:

4

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  A: 

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)

Yoni Roit
From what I understand, Socket class is available in AS3, which is Flash Player 9 and higher - any idea on how large is the market segment that will be able to use something written in AS3?
Byteclub
Answering my own comment here, sorry: looked up the stats on adobe.com, looks like flash player 9 is pretty ubiquitous, up to 98.8% of installs use it.
Byteclub
Yes go for as3 - unless your only programming experience up till now has been javascript as2 is not really fun for a programmer and the tools for as3 are much better. (Flash Designers might argue otherwise)
Simon Groenewolt
If you want the Flash to run on Windows Mobile, the swf will need to be targeted for Flash 7 which doesn't have the Socket class.
zooropa
XMLSocket uses TCP but restricts messages to be XML or strings. With Socket, the transmission can use raw binary data.
zooropa
This is what I was looking for.. Given that we already have game servers and a well-defined protocol, Socket class will probably be the best option. Thanks all!
Byteclub
A: 

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

Simon Groenewolt
It's a port of an existing iPhone multiplayer game. Servers are already there. Just trying to figure out if we'll need a different frontend for a Flash implementation or is it possible to simply re-implement and reuse existing protocol (which might save time)
Byteclub
Sockets in flash are tricky (mostly the detecting errors part), xmlsocket is probably the best option. Watch out for people behind restrictive firewalls, you might need a polling http fallback if you want to support them as well.
Simon Groenewolt
A: 

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

zooropa
A: 

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.

justkevin