简体   繁体   English

套接字编程中SOCKS,DIRECT和HTTP之间的区别

[英]Difference between SOCKS, DIRECT and HTTP in Sockets programming

Could someone please advise what the difference is between SOCKS, DIRECT and HTTP type connections in the context of sockets programming? 有人可以告诉我套接字编程上下文中的SOCKS,DIRECT和HTTP类型连接有什么区别吗?

Specifically I am referring to the Android socket classes Proxy type enum but imagine this question applies to other languages. 具体来说,我指的是Android套接字类Proxy类型的枚举,但可以想象这个问题适用于其他语言。

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: 当您使用套接字编写应用程序以与整个Internet进行通信时,尤其是希望使用HTTP的任何应用程序时,您可能处于以下三种不同情况之一:

  1. Direction connection to the internet - you can establish a TCP/IP connection directly to the server at the other end. 与Internet的定向连接-您可以直接建立与另一端服务器的TCP / IP连接。

  2. Connection via SOCKS proxy - you cannot establish a direct connection to the server at the end end. 通过SOCKS代理连接-您无法在末端建立与服务器的直接连接。 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. 相反,您需要使用SOCKS协议与本地LAN安全网关计算机联系,并要求它在最后打开与服务器的连接,打开SOCKS代理服务器的套接字,并通过在您之间转发流量将其修补到服务器和目标服务器(假设本地安全策略允许)。

  3. 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. 通过HTTP代理进行连接-您无法建立直接连接到Internet的连接,或者出于性能(缓存)原因而使用代理很有用。 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. 再一次,您无需通过另一端打开与服务器的连接,而是通过HTTP协议打开了与您附近的HTTP代理服务器(可能在您的LAN上或可能在您的LAN上)的连接,并要求它代表您进行与终端设备的HTTP事务。

These are the 3 situation described by the enum values. 这是枚举值描述的3种情况。

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). 在这种情况下,您根据方案1(定向连接)进行操作,但实际上您在方案3(HTTP代理)中。 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). 从目标服务器到HTTP代理的重定向是通过LAN上的网络设备(通常是路由器,有时是交换机)透明进行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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