My would recommendation would be to use Jabber (XMPP).
several Jabber servers, with different capabilities and features. If
you don’t want something too complicated and don’t need the features
some of the more complex solutions provide, I would suggest to take a
look at Prosody.
For the client, I would suggest looking at Pidgin.
Both are open source.