Difference between SOCKS, DIRECT and HTTP in Sockets programming
Could someone please advise what the difference is between SOCKS, DIRECT and HTTP type c开发者_C百科onnections in the context of sockets programming?
Specifically I am referring to the Android socket classes Proxy type enum but imagine this question applies to other languages.
When you write a an application using a socket to communicate with the Internet at large, specifically anything that wish to use HTTP, you might be in one of 3 different situations:
Direction connection to the internet - you can establish a TCP/IP connection directly to the server at the other end.
Connection via SOCKS proxy - you cannot establish a direct connection to the server at the end end. Instead you need to contact the local LAN security gateway computer using the SOCKS protocol and ask it to open a connection to the server at the end, open a socket to the SOCKS proxy server and have it patch you through to server by forwarding traffic between you and the target server, assuming the local security policy allow that.
Connection via a HTTP proxy - you either cannot establish a direct connect to the internet or it is useful to use a proxy for performance (caching) reasons. Once again, instead of opening a connection to the server at the other end you open a connection to the HTTP proxy server close to you (which may or may be on your LAN) via the HTTP protocol and ask it to conduct on your behalf an HTTP transaction with the end device.
These are the 3 situation described by the enum values.
In reality, a 4th situation exists - that of the transparent proxy, but as the name implies your code is not aware of it, hence it is not represented by an enum value. In this situation you act according to scenario 1 (direction connection) but in reality you are in scenario 3 (HTTP proxy). The redirection from your target server to the HTTP proxy happens transparently by the networking gear on the LAN (usually a router, sometime a switch).
精彩评论