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