[Red5] Bug: Reading AMF3 arrays from Flash
Tyler Kocheran
rfkrocktk at gmail.com
Tue Aug 12 10:20:38 PDT 2008
Andy,
I'm working directly with externalizable custom classes in AS3, not
"directly" passing arrays, so I'm not sure if this applies. The problem is
that I'm not getting any errors at all, but I've deduced that the errors are
happening in my readExternal() class in my Red5 custom object class. I just
get a silent fail and no result fired signaling that the call has been
completed on the serverside. The problem has to do with the way that Red5
reads external classes from AS3.
- TK
On Tue, Aug 12, 2008 at 9:15 AM, Andy Shaules <bowljoman at hotmail.com> wrote:
> TK,
>
> Dunno if it helps or relavent but as I recall amf0 sending arrays is like
> sending multiple arguments to java, but in amf3 sending an array, is sending
> a single argument of type array.
>
> If my memory serves me correctly...
>
> amf0 nc.call("indexOutOfBounds", new Array("0","1","2","3")) in java you
> will have param[3] ="3"
> amf3 nc.call("indexOutOfBounds", new Array("0","1","2","3")) in java you
> will have param[3] =ArrayIndexOutOfBoundsError
>
> Also, latest flash player defaults to amf3 so it is now neccessary to set
> default encoding, or require higher version.
>
> All this is from some work a coulple months ago, so I hope my memory isnt
> too fuzzy.
>
> Andy
>
>
>
>
> ----- Original Message -----
> *From:* Tyler Kocheran <rfkrocktk at gmail.com>
> *To:* red5 at osflash.org
> *Sent:* Tuesday, August 12, 2008 8:53 AM
> *Subject:* Re: [Red5] Bug: Reading AMF3 arrays from Flash
>
> Ok, so I've discovered the real problem.
>
> When I serialize an array in AS3 and send it to Red5, I'm writing it as an
> object via writeObject(). When I read the object on the serverside via Red5,
> I'm reading it with readObject() which returns an Object. Now, when I'm
> reading this object, I'm desiring to convert it into a Set or a Collection
> of some sort and I can't directly read it that way. Even if I try to read
> the object as a Object[] array, I get a silent fail. ( Object[] arr =
> (Object[]) input.readObject() ) It seems that this is where all failing is
> happening, when I try to cast the returned value as any sort of array or
> collection. Does anyone know if this has been updated in the current trunk?
> I'll make sure to look into it.
>
> Also, I haven't yet tried writing the Array as a byte-array and reading it
> as such on the serverside. I've experimented with writing the Collection as
> an object on the serverside and reading it that way on the clientside, and
> that works, suprisingly. It seems that Red5 can write the
> Collection/Set/Array as an object and AS3 can read it as an object casted to
> an Array, but Red5 can't read an Array sent from AS3 and cast it as an
> Array. If I try printing the value of readObject(), I get an array(!):
> ["one", "two", "three", "four"], but I can't cast it that way, ever. In the
> next version of Red5 (perhaps 0.7.1), could we get a "readObjectAsArray()"
> method in the IDataInput interface? I'm definitely willing to donate some
> time on making that work, if I knew how to.
>
> So there's definitely a bug here with reading Arrays on Red5's side. I'm
> going to try a few things to see if they help:
> 1. Try using a ByteArray on AS3's side and a corresponding byte[] on Red5's
> side to serialize the Array.
> 2. Test the application on the latest trunk version of the server.
>
> Has anyone else encountered this bug, and workarounds?
>
> - TK
>
> On Fri, Aug 8, 2008 at 12:12 AM, Tyler Kocheran <rfkrocktk at gmail.com>wrote:
>
>> I think I just uncovered a huge bug in 0.7 relating to externalization of
>> classes.
>> The thought is this, a developer should be able to create a class in AS3
>> which implements IExternalizable, a class in Java that also implements
>> IExternalizable, and send them back and forth over Red5. The bugs that I
>> have found in doing this is that Red5 can't figure out what to do with a
>> read object that has been sent from Flash if that value is an array. If I
>> try sending these custom classes to Red5 that have arrays, it works out just
>> fine. However, as soon as I implement Sets and Collections on the server
>> side that read the serialized object back as a Set<?> or a Collection<?>,
>> Red5 fails silently. Here's my flow of information:
>>
>> I send a class instance via a remoting call to Red5. Red5 grabs the
>> instance, recognizes it as the class I registered it as
>> (registerClassAlias), and then proceeds to store the instance to a database
>> with Hibernate. Hibernate doesn't support using simple Object[] arrays, it
>> depends off of the Collections package to determine what the values are in
>> the arrays. In my serverside externalized class.
>>
>> Every time I try reading the written object as a Collection<String>, Red5
>> fails silently in the middle of the call. This is my code:
>> @SuppressWarnings (value="unchecked")
>> public void readExternal(IDataInput input) {
>> this.stringSet = (Set<String>) input.readObject();
>> ...
>> }
>>
>> By outputting each value as it has been serialized, I can tell where the
>> fail happens and it is always at this line. I have tried numerous things to
>> get around this, such as something like this:
>> Object[] whatever = (Object[]) input.readObject();
>> for (int i = 0; i < whatever.length; i++) {
>> stringSet.add((String) whatever[i]);
>> }
>> However, this fails immediately in the very first line. It seems that the
>> casting of the input variable causes Red5 to silently fail.
>>
>> I have not tried using wildcards in my Collection assignments, maybe I
>> should do that. Has this bug come up with anyone else before, and are there
>> any known fixes? For the project I'm working on right now, this is
>> absolutely essential to its success. Is there any other way of reading the
>> value of the sent array? I don't know how to work with byte-arrays, should I
>> try that and how should I implement it?
>>
>> Any ideas?
>>
>> - TK
>>
>> --
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>> And do this, knowing the time, that now it is high time to awake out of
>> sleep;
>> for now our salvation is nearer than when we first believed.
>>
>
>
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> And do this, knowing the time, that now it is high time to awake out of
> sleep;
> for now our salvation is nearer than when we first believed.
>
> ------------------------------
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
>
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
>
>
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
And do this, knowing the time, that now it is high time to awake out of
sleep;
for now our salvation is nearer than when we first believed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5_osflash.org/attachments/20080812/76439d2f/attachment-0001.html
More information about the Red5
mailing list