简体   繁体   中英

Using Java Socket vs. Apache HttpClient for asynchronous real-time HTTP data gathering

I had a quick conversation with a co-worker who asked if I knew how to use Java Socket for real-time data gathering in an Android app from an HTTP web server. I am only familiar with using Apache's HttpClient, HttpPost, HttpResponse, classes.

What are the advantages of using the java.socket class vs. org.apache.http.client.HttpClient class for instantiating and running multiple HTTP Get requests for real-time data?

This is what I know and it may help you:

socket is just provide you two Transport layer Protocol TCP/UDP . HTTP is an application layer protocol on top of TCP . so if you want to communicate to an HTTP server you must talk to it with HTTP protocol. you can reinvent the wheel and implement the HTTP protocol using java.socket by yourself or use HttpUrlConnection or org.apache.http.client.HttpClient or OKHTTP . All of them are using socket to access web server under the hood.

What are the advantages of using the java.socket class vs. org.apache.http.client.HttpClient class for instantiating and running multiple HTTP Get requests for real-time data?

So in my opinion there is no advantage to use java.socket to communicate to an HTTP server unless you need a feature that dose not exist in any of those libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM