2

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 proxy 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;
}

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.