tags:

views:

428

answers:

1

Hello,

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.

+2  A: 

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

fvu
I'm not entirely sure, It's a squid proxy server is as far as I know.
HannesNZ
Squid can be configured to support SOCKS but it doesn't do so by default. Do remember though that companies put proxies as much to disallow "wild" outgoing traffic as to keep undesired incoming traffic out of the network. It could very much not work "by design". There are ways around this limitation, like http://www.ericdaugherty.com/dev/soht/, but if the proxy doesn't handle this kind of traffic on purpose your employer may not like that kind of creativity...
fvu
So how do i connect through an HTTP proxy with UDP?
HannesNZ
There's no straightforward way to do that, you always need assisting infrastructure. Like the aforementioned SOHT, a solution that wraps network packets (UDP or TCP) in http requests and answers. You'll need a SOHT server set up on the "outside" to retranslate the packets for you.
fvu