I am having trouble implementing socket using actionscript. I have a
server that does some calculations and displays data in csv format
every 5 seconds.
Every 5 seconds the data is calculated and send thr socket to the
actionscript. The first line is always the header line. The column
names and number is same for all the data. Only the data value is
changing. The columns are then displayed in advanceddatagrid. I have
everything working correctly except grabbing the data via socket.

The front end is in flex/action script. It connects to server . But in
every run of onSocketData I only get the last part of the data. I
cannot get the entire data that the server has sent. How can I loop
thr in on SocketData function for the entire data that the server has
sent and assign it to the label ( for now ) . so every 5 seconds the
lbl will get refreshed with the new data. Currently it only has the
data for the last snap.

Is there any example where the socket connection is kept and the data
that is send via socket captured completely on the flex side.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
creationComplete="init()" layout="vertical">


<mx:Script>
<![CDATA[

import mx.controls.Alert;
import flash.display.Sprite;
import flash.events.ProgressEvent;
import flash.net.Socket;
import flash.utils.ByteArray;
import flash.errors.EOFError;
import mx.collections.ArrayCollection;

public var srv:Socket = new Socket();
public var dataRecv:String = new String();




public function init():void {

srv = new Socket();
srv.addEventListener(Event.CONNECT, onConnect );
srv.addEventListener(IOErrorEvent.IO_ERROR,onError );
srv.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData );
srv.connect( "localhost", 8000 ) ;
srv.flush();

}

private function onConnect ( event:Event ) : void {
Alert.show ( "Socket Connection Sucessfull" ) ;
}

private function onError ( event:Event ) : void {
Alert.show ( "Socket Connection Failed " + event.toString() ) ;
}


private function onSocketData ( event:ProgressEvent ) : void {

var buffer:ByteArray = new ByteArray();

srv.readBytes(buffer, buffer.length, srv.bytesAvailable);

lb1 = buffer.toString()
// this is where tthings go wrong. The srv.bytesAvailable only
processes certain amount of data and I only get the last processed
data

}

]]>
</mx:Script>
<mx:Label id="lb1"/>
</mx:Application>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to