We will describe the message format used in libnjaim briefly, you could download the udpserver freely from http://sourceforge.net/projects/njaim
Client can send one of four kinds of message to udpserver (When we talk about proper string, we mean a string without space and '=') :
Login message, format : "TYPE=LOGIN NAME=logname", NAME field can be any proper string. Client must send this message first to make himself logged in.
Logout message, format : "TYPE=LOGOUT". Client send this message to logout.
Check message, format : "TYPE=CHECK". Since udpserver will kick a client after 60s of idle, client should at least send a check message every 60s.
Other message, format : "TYPE=typestr NAME=namestr TEXT=textstr", TYPE, NAME and TEXT fields can be any proper string, the TEXT field is optional. When client send this message to udpserver, the latter will relay this message to the client named "namestr" in a format we will talk about later.
Client can receive one of four kinds of message from udpserver :
OK message 1, format : "TYPE=OK". Client will receive this message when LOGIN, LOGOUT or CHECK messages are accepted by udpserver.
OK message 2, format : "TYPE=OK PEER=namestr/addrstr". Client will receive this message when he sent "other" message to udpserver, and the peer referred in the message is logged in.
Error message, format : "TYPE=ERROR TEXT=errstr". Client will receive this message when his request is refused by udpserver, along with a short description.
Other message, format : "TYPE=typestr PEER=namestr/addrstr TEXT=textstr". Client will receive this message when another client sent him an "other" message, the typestr and textstr remain the same, but namestr and addrstr are replaced by the login name and Internet address of the peer.
Since UDP is not reliable, sometimes we want to be assured that the message is successfully received by peer, we may require the peer to acknowledge the message. This can be done by sending messages of type "ACK", with an empty TEXT field.
Here is a common scenario :
Alice sends : "TYPE=CUSTOM NAME=Bob TEXT=hello".
Alice receives : "TYPE=OK PEER=Bob/1.2.3.4:5".
Bob receives : "TYPE=CUSTOM NAME=Alice/4.3.2.1:5 TEXT=hello".
Bob acknowledges by sending : "TYPE=ACK NAME=Alice".
Bob receives : "TYPE=OK PEER=Alice/4.3.2.1:5".
Alice receives : "TYPE=ACK PEER=Bob/1.2.3.4:5".