When using TCP sockets, this task will not be a good idea, since you will have to take care of many things, such as message formatting, streaming, etc. Use one of the available protocols and messaging libraries.
I would suggest looking into XMPP , which has a set of open standards for messaging between devices. The advantage is that there are many libraries for implementing both XMPP clients and servers.
To implement the XMPP client on Android devices, you can use the Smack library. This is actually a Java based library. I implemented the Facebook XMPP chat client using Asmack , which is Smack's Android port. The Smack documentation is also applicable to Asmack. However, Asmack has not been updated for two years and has some problems, and I thought about changing my client to Smack to find out if the new version works well with Android.
Regarding the implementation of the XMPP server, you can check out Openfire made by the same guys who made Smack. I have not used this yet, but there is extensive documentation on setting up Openfire on the project page. Judging by the quality of the Smack library I used, I believe that Openfire will work just fine.
Good luck
Vinay s shenoy
source share