views:

841

answers:

1

What is the best way to implement async json socket communication between Flex client and custom server?

Is there a library that can listen to socket and fire event when complete json message/object is raceived?

EDIT: I know that I can use Socket and listen to SOCKET_DATA event, but that triggers event whenever new data is received, while I need to be notified only when (complete) jton object is received.

I was hoping for something more automatic :)

+1  A: 

You'll need to use the Socket class for that. The socketData event is triggered when new data is received. There are also events that get fired when the connection opens and closes or when you have an io or security error.

If you're using AIR, you can also use the SocketMonitor to monitor your server endpoint.

Christophe Herreman
I know that I can use Socket and listen to SOCKET_DATA event, but that triggers event whenever new data is received, while I need to be notified only when (complete) jton object is received.
Dev er dev
I see. Well I think you'll need to make sure that your server sends an extra token at the end to indicate the end of the json string. Additionaly you'll have to subclass Socket and check the received data for the extra token and then dispatch a custom event. The XMLSocket uses a zero byte at the end
Christophe Herreman