![]() |
|
#1
|
|||
|
|||
|
Hello all,
Recently I had some problem to pass long string (>64Kb) from my wowza app to flash client. Wowza throws exception: Code:
java.io.UTFDataFormatException: encoded string too long: 66826 bytes at com.wowza.wms.amf.AMF3Utils.serializeStringNoLength(Unknown Source) at com.wowza.wms.amf.AMFDataItem.serialize(Unknown Source) at com.wowza.wms.amf.AMFDataList.serialize(Unknown Source) at com.wowza.wms.amf.AMFDataList.serialize(Unknown Source) at com.wowza.wms.response.ResponseFunction.write(Unknown Source) at com.wowza.wms.response.ResponseFunction.write(Unknown Source) at com.wowza.wms.response.ResponseFunctions.output(Unknown Source) at com.wowza.wms.request.RTMPRequestAdapter.service(Unknown Source) at com.wowza.wms.server.ServerHandler.serviceRequest(Unknown Source) ERROR server comment - serialize: java.io.UTFDataFormatException: encoded string too long: 66826 bytes wowza java code Code:
public void send(String xml) {
String[] chunks = FCWzVideochatUser.splitString(xml, 65535);
AMFDataArray longStrArr = new AMFDataArray();
for (int i=0; i<chunks.length; i++) {
longStrArr.add(new AMFDataItem(chunks[i]));
}
iclient.call("receive", new FCWowzaResult(), longStrArr);
}
public static String[] splitString(String str, int maxLength) {
if (str==null) return null;
int len = str.length();
int fullChunks = len / maxLength;
boolean lastChunkEmpty = fullChunks*maxLength == len;
int size = fullChunks;
if (!lastChunkEmpty) size++;
int i = 0;
String[] chunks = new String[size];
for (i=0; i<fullChunks; i++) {
chunks[i] = str.substring(i*maxLength, i*maxLength+maxLength);
}
if (!lastChunkEmpty) chunks[i] = str.substring(i*maxLength, len);
return chunks;
}
Code:
function clientResult(longStrArr:Array)
{
var xml:String = "";
for(var i:Number = 0;i< longStrArr.length;i++)
xml += longStrArr[i];
}
Charlie, thanks a lot. |
|
#2
|
|||
|
|||
|
Thanks for posting this code. Quick not is that this is not an issue if you use AMF3 encoding (which is the default for ActionScript 3.0).
Charlie |
|
#3
|
|||
|
|||
|
Depending on how your client side functions are designed, you may not need to change them. If your functions are expecting a string and you pass an array of strings, Actionscript will automatically call a .toString() on the array and it'll magically turn into the reassembled string.
Your mileage may vary, but this behavior just saved me a ton of work. ![]() EDIT: Ignore that post, I'm an idiot. The default .toString() throws a comma in at the point where the array members are joined, which will cause some very strange behavior if you use that string for XML. Use the code posted above on the client side, don't rely on the default .toString(). Last edited by FlyingPotatoes; 03-23-2009 at 05:09 PM. |
|
#4
|
|||
|
|||
|
Quote:
According to the JavaDocs it's a limitation of the Java function writeUTF() so it's recommended to use another method or just doing it by yourself. Splitting the string up is not an option for my case because I use the big UTF8 string (having xml data) in a shared object slot so I would need to handle multiple slots for just one file, that's too confusing. So, what else can I do to work around the problem? Robin dpMediaDev Last edited by dpMediaDev; 07-07-2009 at 04:53 AM. |
|
#5
|
|||
|
|||
|
There is a limit of 64K on both AMF0 and AMF3 strings. You can still store the string in a single slot by breaking it up into multiple Strings and store an AMFDataArray of strings in the shared object slot. It should do everything you need. Then you just need to marshall it on either end.
Charlie |
|
#6
|
|||
|
|||
|
Quote:
But in the other direction it doesn't work. So in the client I create an array of strings, put it in the shared object and on the server side I want to get it from the shared object as an AMFDataArray. But the casting fails because now it's a AMFDataMixedArray. What's the reason for that? On the client I just put in an array of strings and not an array of any datatype. Robin dpMediaDev |
|
#7
|
|||
|
|||
|
Then I would just switch everything to use AMFDataMixedArray. The Flash player tends to always serialize using this format. Not sure why.
Charlie |
|
#8
|
|||
|
|||
|
Quote:
So this Mixed Array has all things I need, that's ok. Sincerely, Robin dpMediaDev |
![]() |
| Thread Tools | |
| Display Modes | |
|
|