簡體   English   中英

通過Delphi中的代理進行UDP連接

[英]UDP Connection through proxy in Delphi

我有一個連接到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;

我不知道我在做什么錯,我沒有使用太多代理,它在工作中不起作用,而且不是工作項目,因此我無法在那里進行調試。

提前致謝。

您知道TransparentProxy必須是SOCKS5代理嗎? 您正在使用哪種代理進行測試?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM