I looked into this previously and was interested most by XMPP. You can use open source servers like Openfire (Java, http://www.igniterealtime.org/projects/openfire/index.jsp) or eJabberd (Erlang, http://www.ejabberd.im/). It's more instant messaging than chatting, though (although it does support multi user chat)