To answer Q's 1, 3 and 4:
The XMPP Protocol itself covers most of what you will need from a modern-day IM app (you stated WhatsApp - they used it, at least at the starting phase, same goes for the Facebook messaging app). I'm guessing that's what you're aiming at.
There are other well known options like IRC, - again, it depends on what you need, I suggest reading up about it: XMPP.
By "develop an IM app", I'm assuming you mean starting with mobile, in that case there's a well documented library for Android called Asmack, it will help you in writing your own client (again, read up...)
Continue by looking at which Server implementation of the XMPP protocol suits you best, among the common implementations out there are Ejabberd and OpenFire,
Have a look at this: XMPP Server Comparison (the "pre-cooked" ref)
Some things to consider as an independent developer:
- Open-Source.
- Community Support and Documentation.
To try and answer Q 2:
The "pre-cooked" servers, combined with the client libraries will probably cover the sockets for you.
Edited:
You should probably also give this SO Thread a look: Android and XMPP: Currently available solutions
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…