Delphi中通过代理进行UDP连接

发布于 2024-08-07 13:49:31 字数 1126 浏览 3 评论 0原文

我有一个连接到 udp 服务器的应用程序,当我位于代理后面时,我似乎无法启动它。

这是我的代码,当不在代理后面时,它工作正常。

function TfrmMain.SendCommand(ServerName, IP: String; Port: Integer; Command: String): String;
var
  Udp : TIdUDPClient;
  Count : Integer;
  Response: String;
begin
  Result := '';
  Udp := TIdUDPClient.Create(nil);
  try
    try
      Udp.Host := IP;
      Udp.Port := Port;
      if UseProxy then begin
        Udp.TransparentProxy.Enabled := True;
        Udp.TransparentProxy.Host := ProxyServer;
        Udp.TransparentProxy.Port := ProxyPort;
        Udp.OpenProxy;
      end else begin
        Udp.TransparentProxy.Enabled := False;
      end;
      Udp.Connect;
      if Udp.Connected then begin
        //Send Command and receive data...
      end;
      if UseProxy then begin
        Udp.CloseProxy;
      end;
      Udp.Disconnect;
    except
      MessageBox(Handle, PChar('There was an error connecting to server ' + QuotedStr(ServerName) + '.  '), 'Error', MB_ICONERROR);
    end;
  finally
    Udp.Free;
  end;
end;

我不知道我做错了什么,我没有太多使用代理,而且它在工作中不起作用,而且它不是一个工作项目,所以我无法在那里调试它。

提前致谢。

I have an application that connects to a udp server, and I can't seem to get it going when I am behind a proxy.

Here is the code I have, which is working fine when Not behind a proxy.

function TfrmMain.SendCommand(ServerName, IP: String; Port: Integer; Command: String): String;
var
  Udp : TIdUDPClient;
  Count : Integer;
  Response: String;
begin
  Result := '';
  Udp := TIdUDPClient.Create(nil);
  try
    try
      Udp.Host := IP;
      Udp.Port := Port;
      if UseProxy then begin
        Udp.TransparentProxy.Enabled := True;
        Udp.TransparentProxy.Host := ProxyServer;
        Udp.TransparentProxy.Port := ProxyPort;
        Udp.OpenProxy;
      end else begin
        Udp.TransparentProxy.Enabled := False;
      end;
      Udp.Connect;
      if Udp.Connected then begin
        //Send Command and receive data...
      end;
      if UseProxy then begin
        Udp.CloseProxy;
      end;
      Udp.Disconnect;
    except
      MessageBox(Handle, PChar('There was an error connecting to server ' + QuotedStr(ServerName) + '.  '), 'Error', MB_ICONERROR);
    end;
  finally
    Udp.Free;
  end;
end;

I don't know what I'm doing wrong, I haven't worked with proxies much, and it is at work that it doesn't work, and it's not a work project, so I can't debug it there.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-08-14 13:49:31

您知道TransparentProxy必须是SOCKS5代理吗?您使用哪种代理进行测试?

You are aware that the TransparentProxy must be a SOCKS5 proxy? What kind of proxy have you been testing with?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文