trying to implement Obj C room.setAttribute...

Added by Ransom Weaver 518 days ago

I'm implementing a rather simple multiuser system with an (existing) native iphone app setting an attribute and a swf displaying the value. I'm using kenichi's obj c code.

For my first test I used a swf to set the attribute using an interval:

protected function tick():void {
cr.setAttribute('ct',ct.toString());
ct++;
}

receiving swf listens for AttributeEvent.UPDATE

protected function tick(e:AttributeEvent):void {
trace("new value: "+e.getChangedAttr().value);
if (e.getChangedAttr().name == "ct") {
tf.text = e.getChangedAttr().value;
}
}

All good. swf trace:
9/4/10 10:05:21.891 UTC-4 INFO: [ROOM id: imi_test] Setting attribute [ct]. New value: [12]. Old value: [11].
Now I want to do that setAttribute from Obj C. kenichi's code doesn't have a room.setAttribute function but it's easy to implement:

In Room.m:
-(void)setAttribute:(NSString*)theAttr withValue:(NSString*)theVal {
/> }

In RoomManager.m:
-(void)setAttribute:(NSString*)theAttr withValue:(NSString*)theVal andRoomName:(NSString*)roomName{
/> }

In Reactor.m:
- (void)sendu5withAttr:(NSString )theAttr andValue:(NSString *)theVal andRoomName:(NSString)roomName {
NSString *postData = [upc makeUPC:@"u5" withArgs:[upc makeArgs:roomName,theAttr,theVal, nil]];
/> }

In UPC.m: (unchanged from kenichi)
-(NSString *)makeUPC:(NSString *)upcID withArgs:(NSString *)args {
NSString *string = [NSString stringWithFormat:"data=&lt;U&gt;&lt;M&gt;%</M><L>%@</L></U>", upcID, args];
return [self pushReqIDAndSessionID:string];
}

-(NSString *)makeArgs:(NSString *)args, ... {
NSMutableString *a = [NSMutableString string];
NSString *eachObject;
va_list argumentList;
if( args != nil ){
/> va_start(argumentList, args);
while((eachObject = va_arg(argumentList, NSString *)) != nil){
/> }
va_end(argumentList);
}
return a;
}

The iphone app joins the room successfully: the flash output console traces this when the iphone app joins the room:

9/4/10 10:08:22.428 UTC-4 WARN: [CLIENT_MANAGER] getInternalClient() called for unknown client ID: [27210].
9/4/10 10:08:22.487 UTC-4 INFO: [CLIENT clientID: 27210, userID: ] Setting attribute [_CT]. New value: [1283609301468]. Old value: [null].
9/4/10 10:08:22.489 UTC-4 INFO: [ROOM id: imi_test] New occupant count: 2
9/4/10 10:08:22.490 UTC-4 INFO: [ROOM id: imi_test] Added occupant: [27210].

HOWEVER, once the iphone starts sending data with u5, there is never any indication of a attribute value change in the swf output. Meanwhile over on the Xcode log, the iphone is merrily sending and receiving this:

0x2061c0/-[Reactor sendUPCwithData:] (Reactor.m:133) >>>: data=<U><M>u5</M><L><A>imi_test</A><A>ct</A><A>8</A></L></U>&requestID=26&sessionID=0ad038b8-4d0c-4c13-ade0-7ad455e9c8c6
0x2061c0/-[Reactor sendUPCwithData:] (Reactor.m:139) BEGIN: <NSURLConnection: 0x6628c30, http://tryunion.com:80>
0x2061c0/-[Reactor connection:didReceiveData:] (Reactor.m:160) <<<: <U><M>u74</M><L><A>imi_test</A><A>ct</A><A>SUCCESS</A></L></U>
0x2061c0/-[Reactor parser:didEndElement:namespaceURI:qualifiedName:] (Reactor.m:200) no react method for u74, data:(
"imi_test",
ct,
SUCCESS
)
0x2061c0/-[Reactor connectionDidFinishLoading:] (Reactor.m:148) FINISH: <NSURLConnection: 0x6628c30, http://tryunion.com:80>

If instead of looking for AttributeEvent.UPDATE I poll on an interval and do trace('ct: '+cr.getAttribute('ct'));
I just get null, even though the iphone is supposedly successfully sending <U><M>u5</M><L><A>imi_test</A><A>ct</A><A>8</A></L></U>

Any ideas where this is breaking down?

Many thanks,

Ransom


Replies

RE: trying to implement Obj C room.setAttribute... - Added by Ransom Weaver 518 days ago

formatting problem with the Obj C code, I'll try pre tags:

In Room.m:
-(void)setAttribute:(NSString*)theAttr withValue:(NSString*)theVal {
    [rm setAttribute:theAttr withValue:theVal andRoomName:name];
}

In RoomManager.m:
-(void)setAttribute:(NSString*)theAttr withValue:(NSString*)theVal andRoomName:(NSString*)roomName{
    [r sendu5withAttr:theAttr andValue:theVal andRoomName:roomName];
}

In Reactor.m:
- (void)sendu5withAttr:(NSString *)theAttr andValue:(NSString *)theVal andRoomName:(NSString*)roomName {
    NSString *postData = [upc makeUPC:@"u5" withArgs:[upc makeArgs:roomName,theAttr,theVal, nil]];
    [self sendUPCwithData:postData];
}

In UPC.m: (unchanged from kenichi)
-(NSString *)makeUPC:(NSString *)upcID withArgs:(NSString *)args
{
    NSString *string = [NSString stringWithFormat:@"data=<U><M>%@</M><L>%@</L></U>", upcID, args];
    return [self pushReqIDAndSessionID:string];
}

-(NSString *)makeArgs:(NSString *)args, ...
{
    NSMutableString *a = [NSMutableString string];
    NSString *eachObject;
    va_list argumentList;
    if( args != nil ){
        [a appendFormat:@"<A>%@</A>", args];
            va_start(argumentList, args);
            while((eachObject = va_arg(argumentList, NSString *)) != nil){
                [a appendFormat:@"<A>%@</A>", eachObject];
            }
            va_end(argumentList);
    }
    return a;
}

RE: trying to implement Obj C room.setAttribute... - Added by Ransom Weaver 518 days ago

Also, there are no server >> client u9 messages in the xcode console that would indicate a change of attribute in the room....

RE: trying to implement Obj C room.setAttribute... - Added by Ransom Weaver 517 days ago

I've changed this over to Client attributes. Works good swf to swf. Same problems with iphone though.

I'm concerned about two things:

1) do I have the update levels set correctly
i have this before my room join:
[reactor sendu64withRoomName:roomName andUpdateLevel:@"7"];

Is that the correct integer for setting the first 3 bits to 111? 2) do I have the correct scope and options for u3? I am using this:
[self sendu3withClientID:selfID andUserID:selfUserID andAttrName:theAttr andEscapedAttrValue:theVal andAttrScope:@"imi_test" andAttrOptions:@"1"];

this returns -[Reactor reactu73] (Reactor.m:344) reacting u73 [SET_CLIENT_ATTR_RESULT] clientID=28245, attrName=COUNT, attrOptions=1, status=SUCCESS

Iv'e tried no scope, no options, different options, But no love on the flash side.

RE: trying to implement Obj C room.setAttribute... - Added by Ransom Weaver 516 days ago

Ok, I have sussed the problem. Indeed it is that I did not have the u3 options set correctly. I set the reactor log level of my test swf to Debug and was able to see that it needed to be 4 in order to set the Attribute to Shared. setting this in my Obj C function solved the problem.

My confusion was trying to figure out from the UPC Specification what integer to use. for u3:

0 - RESERVED
1 - RESERVED
2 - shared
3 - persistent
4 - unique
5 - RESERVED BY SERVER
6 - RESERVED BY SERVER
7 - RESERVED BY SERVER
8 - evaluate

It was not clear to me that I don't count the reserved as part of the binary number, so what I need is 100, or 4 to get shared, not persistent, not unique. I list of integers and what they switch on and off would be very helpful in the docs.

Now what my Obj c is sending is being propagated to the other connected users. Huzzah.

On another matter, is there any likelihood of tryunion.com being changed off the current version before Sept 25? I'm going to be showing a prototype to a client at that time and I'd like to not get caught flat footed by version issues. I could set up my own server if need be.

I'm really exited about Union Platform! Its just what I needed.

thanks,

Ransom Weaver

RE: trying to implement Obj C room.setAttribute... - Added by colin moock 514 days ago

> It was not clear to me that I don't count the reserved as part
> of the binary number, so what I need is 100, or 4 to get shared,
> not persistent, not unique. I list of integers and what they
> switch on and off would be very helpful in the docs.
--
...but you do count it. 0: reserved, 1: reserved, 2: shared. so this gets you shared:

bit:   210
value: 100

the bit values are in the spec (http://unionplatform.com/specs/upc/). are you missing any information?

> On another matter, is there any likelihood of tryunion.com
> being changed off the current version before Sept 25?
> I'm going to be showing a prototype to a client at that time
> and I'd like to not get caught flat footed by version issues.
> I could set up my own server if need be.
--
the tryunion.com build today will be compatible with whatever version is posted sept 25, even if we upgrade it.

> I'm really exited about Union Platform!
> Its just what I needed.
--
us too : ) glad you've got it up and running with your app. let us know if you post any demos for the world to see!

colin

RE: trying to implement Obj C room.setAttribute... - Added by Ransom Weaver 514 days ago

I think I've just been dense is all. So to do persistent and shared we would have
bit:       3210
value:  1100
integer: 12
and persistent but not shared:
bit:       3210
value:  1000
integer: 8

This what you get with self-taught programmers :-) But I'll bet this is in one of your books....

I'll be sure to post up a link when I get this in shape. The app is this: http://imobileintervals.com/app, to which I've recently added ANT+ wireless fitness sensor compatibility, and Union Platform is going to provide the push to make realtime data telemetry possible. Eventually the client for viewing the data will be 1) tied into the website (Drupal with organic groups: see a grid of the live data of all the transmitting users in the group, e.g. a cycling team). 2) an embeddable player so that anyone can put the live data of a user or group of users on their website/blog. I'm starting out with swfs because its so easy, but ultimately I'm going to want to use Orbiter so I can have an iOS-friendly web app. Maybe by the time I get to that there will be some example code floating around.

I've already got it working (it's really very basic), I just need to pretty up the data widget. Plan is to demo all this in 2 weeks at Interbike, the big annual bicycle industry trade show in Las Vegas. From a promotional aspect we'd like to get a number of pro cycling teams using this telemetry system in races (i.e. on their websites or with media partners) to display rider heart rate, speed, power (watts) and cadence.

Cheers,

Ransom

RE: trying to implement Obj C room.setAttribute... - Added by colin moock 513 days ago

as it happens, i am a self-taught programmer too : )

bitwise operators were in the first book i wrote, but we had to cut them to save space:
http://www.moock.org/asdg/technotes/bitwise/

very cool app. please do let us know how it evolves!

colin