Delphi中通过代理进行UDP连接
我有一个连接到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您知道TransparentProxy必须是SOCKS5代理吗?您使用哪种代理进行测试?
You are aware that the TransparentProxy must be a SOCKS5 proxy? What kind of proxy have you been testing with?