Networking in Cocoa
Subject:   extend our RCE protocol
Date:   2003-05-29 22:57:06
From:   anonymous2
Our application has a little more thing to do to be perfect. When one guy close the Window or off the line, the other one should know that.

It is quite easy to add these features to our RCE.

In the original protocol, we used _rce_ as the identifier of this protocol's message. And our message should be 3 parts, name and the message. So, it will not appear a message only has 2 parts normally. We can use this feature to extend the protocol.

First, "_rce_:bye" for end of conversation. Within the WindowWillClose method, before we release, we send this message. And if we get this message, we know the guy we are talking with has quited. so we can send a message to the user, and disable the user to enter new message.

Another is so call "Heart beat". When we get a message "_rce_:rut" (rut for r u there?) we reply a message: "_rce_:imh" (imh for I am here). And if we get "_rce_:imh", we set a instance variable alive to YES. And we can set up a timer, to notify us every 10 seconds, whe we get the notification, we check the alive, if YES, we set it to NO, and send a "_rce_:rut" message, if NO, mean that we have heard the other peer's heart beats for 10 second, I think he must die. :) So, give a message to our user.

No more than 20 lines extra coding, you will make your RCE more professional like.

After use this and the tricks I learned from last columns, like change the title according to the user name, and use different color to highlight the user's words. Now it is a real cool IM.

Thanks Mike, you'd really made a great article.