Archive for sockets

New Book

Posted in Uncategorized with tags , , , on April 8, 2010 by bersaelor

My sister got me an Amazon Gift Coupon for easter, so I decided to get a Book about iPhone Programming.

Being quite experienced in the basics I went for “More iPhone 3 Development” by Dave Mark and Jeff LaMarche. So far I really like it, it’s written in a casual voice but not that informal as it would substract from the matter.

It covers NSStreams and establishing Socket Connection but seems to focus on Core Data. As of now I only see minor uses of Core Data to speed up loading and saving of games in my App. Still I might have a look into it once I’m going for the Version 1.1 of the game.

So thanks Dave Mark and Jeff LaMarche for writing the book. I also figured since I learned so much from Jeff’s Blog I had to buy some of his work.

iPhone Client for Multiplayer with NSStreams – Part 2

Posted in Uncategorized with tags , , , on March 7, 2010 by bersaelor

In the first version of the communicator class we were only handling messages that were smaller then 1024 Byte.

To allow it to receive larger messages we need to know when an individual message is finished. Therefore we have to add a unique specifier to the string our server sends, for example “\r\n”. Then we can simply add an “NSMutableString msgBuffer” to our class and another method between the “- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode;” and the “- (void) handleInput: (NSString*)string;” method that does the following:

- (void) processString:(NSString*)string {  
     [msgBuffer appendString:string];
     [string release];
     NSRange r=[msgBuffer rangeOfString:@"\r\n"];
     if (r.location!=NSNotFound) {
          [self handleInput:[[NSString alloc] initWithString:[msgBuffer substringToIndex:r.location]]];
          [msgBuffer setString:@""];
    }
}

Objective C professionals probably realize that I don’t like “autorelease”. The string-argument is supposed to be retained, as is the argument to “[self handleInput]”. I know an object is supposed to be released where it was retained but my original string was retained in “handleEvent” and released in “handleInput” and I didn’t want to change those two methods. This code would not be consistent with the older post otherwise.

iPhone Client for Multiplayer with NSStreams

Posted in Uncategorized with tags , , , , , on March 2, 2010 by bersaelor

When I was learning how to show Models with OpenGL I had the great Tutorials by Jeff Lamarche to help me with. But now that I was facing the development of a client-server pattern to build a multiplayer experience for my game I was stuck, because I couldn’t find any good help here.

Maybe there are others out there who’d appreciate some clarification and sample codes about that, so I’m trying to post something that I would have liked to use, when I was starting with the Topic.

Continue reading