[Spread-users] connecting to spread with Flash

Francis Chary fchary at gmail.com
Thu May 12 14:14:08 EDT 2005

Thanks for the info Jonathan,

Your message is good news and bad news, actually. The XMLSocket in Flash is 
ok with the long-term communication you're talking about, that's the good 
news. It's one tcp connection, that just stays open until you explicitly 
close it. The bad news is that there is no way to control when the onData 
callback is called. Flash basically looks for a single byte with value zero, 
then takes that as end of file and runs the onData function which you've 
defined, with whatever data that has come over the socket before the zero 
byte. The socket remains open, as I understand it. You can't access any of 
the streams directly with Actionscript, I suppose Macromedia is trying to 
keep things simple. My plan was to have the callback put all Spread messages 
(connection and data messages both) into an array, then I could just check 
the array every few milliseconds and pull out the most recent one. The only 
problem is that the onData callback is never run, presumably because Spread 
doesn't send the end of file byte that Flash is expecting at the end of the 

Another stumbling block with Actionscript is that there's no easy way of 
dealing with bytes on their own. You have to use a single-character String 
object, then convert that to ASCII with a String function. This part works 
well enough, it's just annoying, really.

So, it's definitely tricky. Since Spread just assumes that the client knows 
when the message is over, and because Macromedia doesn't let you edit the 
socket code, I think I'll have problems making the Flash onData callback 
work in the way you suggest. I would much prefer to code in the format of 
the message into the Actionscript, but I just don't think it's possible. Is 
there any way I could just edit the server's code to send that extra byte at 
the end of each message? Where would be the best place to look, if I wanted 
to do that?

I really appreciate your help, I'm sorry if I'm asking daft questions.

On 5/12/05, Jonathan Stanton <jonathan at cnds.jhu.edu> wrote:
> Hi,
> They key question seems to be what flash detects as the 'end' of a
> message. If by '0 byte' you mean that a blocking 'read' on teh socket
> returns 0 bytes indicting the socket connection has closed, then that
> will not work with spread.
> Spread opens one tcp connection between the client and server and then
> keeps that conenction open until the client calls SP_disconnect or there
> is a network fault. Each Spread message (whether part of the connect
> sequence, or a distinct data message) is sent on that same tcp
> connection.
> If this XMLsocket is built on the HTTP type model where a new tcp
> connection is established for each data exchange, then that's just not
> going to work. Spread is designed for long-term communication of many
> messages between principles.
> If there is a way to control when XMLSocket calls the callback you could
> code in knowledge of when a complete spread message is received (the
> format of the messages can be determined from the java code that reads
> it in and most of it is fixed sized byte arrays so calculating how many
> bytes to receive isn't too hard) The Spread server does not 'send' any
> signal for end of message, it relies on both ends knowing the message
> format and calculating when a complete message has arrived.
> Hope this all makes sense, even if it sounds like negative news. I don't
> konw Flash at all, so there might be other ways to do this.
> Cheers,
> Jonathan
> On Thu, May 05, 2005 at 03:26:37PM +0530, Francis Chary wrote:
> > Hi there,
> >
> > I'm trying to connect to a spread server with an application written in
> > Actionscript (The language behind Macromedia Flash). I'm essentially 
> porting
> > the java spread client to actionscript as closely as I can, but I'm 
> running
> > into a few problems. I know next-to-nothing about c, so looking at the
> > spread source code hasn't helped me so much.
> >
> > The key difference between java and actionscript as I see it is that the 
> AS
> > XMLSocket object doesn't allow you any access to the lower-level socket
> > streams. You only get two callback methods which are called when the 
> socket
> > recieves some data. You have to put your data handling code in one of 
> these
> > callbacks, and wait for data to come in. Conceptually, this isn't a 
> problem
> > for the porting, I can work around it. The problem seems to be that
> > XMLSocket isn't 'noticing' when data is sent to it, and the callback 
> isn't
> > being called at all. I assume that it has to do with Flash not realising
> > that a stream of data has been terminated. Flash looks for a 0 byte to
> > terminate a stream, is that what the spread server sends?
> >
> > I guess what I'm looking for is the communication that happens in the
> > sendConnect, readAuthMethods and sendAuthMethod methods of the Java 
> client,
> > from the server's point of view. I hope this all makes sense.
> >
> > Thanks
> > Francis Chary
> >
> > --
> > Software Development Intern
> > ABB Corporate Research
> > 4th Floor, East Wing, Khanija Bhavan
> > 49, Race Course Road
> > Bangalore 560 001 India
> > _______________________________________________
> > Spread-users mailing list
> > Spread-users at lists.spread.org
> > http://lists.spread.org/mailman/listinfo/spread-users
> --
> -------------------------------------------------------
> Jonathan R. Stanton jonathan at cs.jhu.edu
> Dept. of Computer Science
> Johns Hopkins University
> -------------------------------------------------------

Software Development
ABB Corporate Research
4th Floor, East Wing, Khanija Bhavan
49, Race Course Road
Bangalore 560 001 India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.spread.org/pipermail/spread-users/attachments/20050512/47328a04/attachment.html 

More information about the Spread-users mailing list