Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将代理设置为套接字?_C#_.net_Sockets_Proxy_Websocket - Fatal编程技术网

C# 如何将代理设置为套接字?

C# 如何将代理设置为套接字?,c#,.net,sockets,proxy,websocket,C#,.net,Sockets,Proxy,Websocket,我想在套接字中使用代理,就像我在webclient中使用代理一样: using(Webclient wb = new Webclient() { wb.Proxy = new WebProxy(); } 我想在此处使用webproxy: public void Connect() { this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); this

我想在套接字中使用代理,就像我在webclient中使用代理一样:

using(Webclient wb = new Webclient()
{
   wb.Proxy = new WebProxy();
}
我想在此处使用webproxy:

public void Connect()
{
    this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    this.socket.Connect(this.whatsHost, this.whatsPort);

    this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, this.recvTimeout);
    this.socket.ReceiveBufferSize = Int32.MaxValue;

    // this.socket.SendBufferSize = Int32.MaxValue;

    if (!this.socket.Connected)
        throw new ConnectionException("Cannot connect");
}

是否有方法在套接字中使用代理?

web代理是。。。那是一个网络的东西。套接字是原始TCP连接,web连接在内部使用套接字。当您使用代理时,固有的套接字将连接到代理端点,并且通过应用程序协议,web客户端将指示它要连接的位置

回答你的问题。。。不可以。套接字是TCP连接,您必须提供要连接的最终端点。代理是应用程序级别的东西