Thursday, February 21, 2008

Push without Flex Data Services

We all know that flex data services is good but is it really neccesary to implement push on flex page?? As a developer with very little money to spend on tools, I was looking out for alternatives.

And Alternative I did find!! The magic is called "XMLSocket"

Though the xmlsocket implementation is depicted as a way for the client and server to talk with xml , there is nothing potentially stopping us from sending just plain text ...

So this is how I did it..

1. Create a java based service that runs on a port (5976 in my case) that spits out content on the port when ever it is available. (This can easily be replaced by a JMS). This includes setting up a thread to write to the socket whenever data is available.

2.Open a xml socket to the server from the flash client.

3. create an ondata handler in the flex part that updates your interface .

There you have it.. :-)

I will be posting the code sample and explanation shortly .. watch out.

Happy flexing.

3 comments:

Buzzy said...

Hi,

I am using another free alternative, WebORB. I find it to be quite impressive. It supports messaging, streaming, remoting, etc..
In fact, I was able to make a simple instant messenger in about 15 after installation on IIS(which is also a no brainer). And since it is an AMF gateway, transfer takes place in binary format which is much faster than the XML based .NET web services I was using earlier.

Buzzy

Anonymous said...

Hi,

can you post a little example code to send xml data from actionscript xmlsocket and java socket...

the xmlsocket seems not working..
for every message, xmlsocket send a backslash zero but java can't undestand it...

thanks a lot

Lord

Vengu said...

I dont have an example with me right now. But you have to watch out for a few things.

You have to appened a new line character after the xml string.

On the java side you have to read with readLine so a new line is neccesary

You can find a great sample here