views:

1935

answers:

3

Hello,

VS 2008

I am using the code below to detect if the client can connect to our sip server. This was working fine. However, the client has changed there network and now my application has to connect to the sip server from behind a proxy server.

The error I get is the "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xx.xx:xx"

This code was working ok, until I have to connect from behind a poxy server.

I could not see any properties there I can add the proxy address to the socket.

Am I missing something?

Many thanks for any suggestions,

public bool IsSIPServerAvailable()
    {
        bool isAvailable = true;
        Socket sock = new Socket(AddressFamily.InterNetwork,
                                 SocketType.Stream,
                                 ProtocolType.Tcp);

        try
        {
            sock.Connect("xxx.xxx.xx.xx", xx);
        }
        catch (SocketException ex)
        {
            Console.WriteLine(ex.Message);
            isAvailable = false;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            isAvailable = false;
        }
        finally
        {
            if (sock.Connected)
            {
                sock.Close();
            }
        }

        return isAvailable;
    }
+1  A: 

This is very similar to this question. I don't think it is possible to create a socket connection through a proxy server. You would need some kind of a protocol and more over, usually administrators set up proxy servers to refuse connections from ports other than standard HTTP, HTTPS.

One solution would be to use tunneling over HTTP.

kgiannakakis
+1  A: 

The whole idea of a proxy is to change the network topology without changing the applications. Thus there is no need to change the app, but a change is required in the proxy configuration/setup.

To check the proxy config independently of your application, you can use Telnet Host Port and see if you get the same timeout/error message or if you get disconnected after entering a few characters.

weismat
+1  A: 

See my answer here, maybe it will be helpful. The general idea is to first establish connection to a proxy, and then use HTTP CONNECT command to open another TCP connection to a given host and port.

Haspemulator