Client not receiving certain messages - please help!

Post here all your questions related with the SmartFoxServer iPhone API

Moderators: Lapo, Bax

willf
Posts: 14
Joined: 01 May 2010, 18:44

Client not receiving certain messages - please help!

Postby willf » 13 May 2010, 21:36

Hi I am writing an iphone game. During client login I send the client a bunch of information about the player (from a custom java extension using raw string protocol).

It seems to work fine except for one particular edge case I found where the last message is never received . or processed.

I went into the code and I changed the read buffer size, and it worked ( in the - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode method) .

Code: Select all

  case NSStreamEventHasBytesAvailable:{
            uint8_t buf[1023];
            NSInteger len = 0;
            len = [(NSInputStream *)stream read:buf maxLength:1023];
}


Note: it is normally 1024

So now is this a possible bug in the client code? Perhaps the packet handling logic doesn't account for some edge case where the packet length is XXX bytes or so?

Or is there something I'm doing wrong on the server side of things that could be causing this.



Please advise.
willf
Posts: 14
Joined: 01 May 2010, 18:44

Postby willf » 13 May 2010, 22:53

After some further tinkering. I got it to work without messing with the buffer size. (since that really wasn't a fix)

Code: Select all

                  //if (start < i) { <--- Removed that            
                  if (YES) { // I ADDED THIS
                     [_receiveLock lock];
                     [_receiveBuffer appendBytes:(const void *)(buf + start) length:(i - start) + 1];
                     NSString *msgStr = [NSString stringWithCString:(const char *)[_receiveBuffer bytes] encoding:NSUTF8StringEncoding];
                     [_receiveBuffer setLength:0];
                     
                     start = i + 1;
                     [self handleMessage:msgStr];
                     [_receiveLock unlock];
                  }


I basically removed that check if (start < i) .

I don't understand the code too well but what I believe was happening was that, the end of a message was at the beginning of the buffer. and when start = 0 and i = 0 it would ignore it, and the processing would skip a message.. i *think*

Can someone clarify? So far this little change - I've seen no negative side effects but perhaps the person who wrote this or someone who understands this code can tell me if this change is appropriate or not.

Thanks!
hasbean
Posts: 43
Joined: 02 Sep 2009, 11:39

Postby hasbean » 24 May 2010, 20:33

This has actually fixed an incredibly annoying bug where I'd get a BAD ACCESS when receiving a long room list with many variables (craps out at the xml parsing part.)

I just wanted to extend my thanks :D I'm using it and I don't see any adverse side effects

Return to “iPhone Objective-C API”

Who is online

Users browsing this forum: No registered users and 1 guest