I am working on developing a mobile application using java for messaging services(P2P) I am still in the early stages, and searching about the best and most suitable protocol for such application. As I have found. socket programming is better than web services. as you know it doesn't need to add extra data (overhead) for the sent message so it will cost lower.
Is there a third option other than sockets & HTTP?
Is socket is the choice what is the best to use TCP or UDP ?!
The question is open for any other options n开发者_JAVA技巧ot only the what is mentioned here and thank you in advance
HTTP and TCP/UDP reside in different layers of the communications systems models (the two most popular being the OSI model and the TCP/IP model). HTTP is built on top of sockets (that's why there's additional overhead), so technically - they are not different solutions.
Using HTTP will give you the advantage of having lots of libraries, documentation and examples to use, while writing your own, custom protocol might take a lot more time and efforts, but would probably be lighter.
If you opt for raw sockets ... I can't tell you if you should use TCP or UDP - that depends on lots of factors, but the basic difference is that a TCP connection would guarantee a successful delivery if there's connectivity available or an error message if not, while UDP just sends the data and doesn't care if it gets there or not (e.g. for streaming live video, there's no point in ensuring that every bit of data is being transferred, as 1 second later it's no longer relevant).
There's no right or wrong answer - you just need to consider all the factors involved and carefully design the whole process.
精彩评论