-----------------------------------
-----------------------------------
Peer2Peer Instant Messaging Network
-----------------------------------
-----------------------------------

TCP: Port 43215

Server = The program that accepts the connection
Client = The program that initiated the connection

Lines starting with S: are sent by the server (without the "S:") and lines starting with C: are sent by the client (without the "C:").
Lines are separated by CRLF.

The following placeholders are used (within <> characters, which are not to be sent):
network = User specified name of the network, may contain ASCII 32 - 126, length: 0 - 64 characters
name = A name that the user picked, may contain ASCII 32 - 126, length: 1 - 64 characters
state = user specified status information, may contain ascii 32-126 and may be empty (contain 0 characters), length: 0 - 256 characters
ips = List of IPs of other clients that the client should connect to in the form: 1.2.3.4;2.3.4.5;123.456.78.9
random = some random characters (ascii 32 - 126), length as definied in the section it is used in
text = the text the user wishes to send to another user. may not contain the string Carriage return + Line feed + ":ENDMSG:" or and ascii character numbers 0 - 31. no other limits regarding length or content

---------------------------------------
Start of session after TCP negotiation:
---------------------------------------
S:IM:NN?
C:MyNet:<network>
Here the server checks if his network is the same as the client's network, if not, the TCP connection is dropped. Otherwise the dialog continues.
S:NetOK
C:MyName:<name>
Now the server checks if the name is a duplicate, if yes, the Server sends "ERROR:DUPLICATE", followed by "DISCONNECT" to the *old* TCP connection and drops the old connection.
S:MyName:<name>
S:LoginOK
Now the server should send a "MyPeers"-message, but in this state, the login procedure is finished. From now on the server and client have to expect every event message as defined below. Also the server and client are now considered as even peers.

--------------------------------
Possible messages between peers:
--------------------------------
Ping:<random>
Length of <random>: 8 characters, suggested characters: A-Z1-9 (but others may also be used)
This message should be sent at regular intervals to check if the receiving side is still active. Suggested time period: 30 - 60 seconds.
When a peer receives this message, it should reply with "Pong:<random>", where <random> are the same characters as received in the "Ping"-message.

Pong:<random>
Length of <random>: 8 characters, suggested characters: A-Z1-9 (but others may also be used)
Reply to the "Ping"-message, the <random> characters should be the same as in the preceding "Ping"-message. If a peer does not receive this response to "Ping" within a reasonable time (suggested: 30 seconds), the peer should sent "ERROR:No Pong" followed by "DISCONNECT" and then drop the TCP connection.

MyName:<name>
This message informs the receiver that the user has changed its name and requests the recieving peer to update its lists.

MyPeers:<ips>
This message should be broadcasted by every peer at regular intervals (~300 seconds?) to allow all peers to check if all peers are connected and allow them to connect missing peers.

ERROR:<message>
DISCONNECT
The peer sending these two lines has recognized an error and will drop the connection. The error message should explain why the connection is dropped, but may not contain more than 256 characters.

Message:
<text>
:ENDMSG:
A message from one user to another user.

DISCONNECT
The peer sending this, wishes to disconnect (e.g. user going offline or the program is exiting). After sending this, the connection can be instantly dropped. If this message is received, the connection should just be dropped as the other peer will likely already have closed the connection. The message is optional, a connection may just be dropped without this message.
