Following is my code that I use to connect windows application to my server, But on office machines where limited access to internet, I can not connect i.e. this code fails. I have to use proxy for this. Please help me in writing proxy for following code.
{
TcpClient client = new TcpClient();
client.Connect("98.130.254.199", 0x599);
client.Close();
}
You can't use proxy with raw sockets (i.e. TcpClient)
except creating your own class derived from TcpClient
and implementing SOCKS or HTTP proxy support.
You'd better use HttpWebRequest/HttpWebResponse pair:
using System.Net;
...
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("98.130.254.199");
request.Proxy = new WebProxy("43.59.90.111", 1080);
request.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
StreamReader reader = new StreamReader(response.GetResponseStream());
Console.WriteLine(reader.ReadToEnd());
...
reader.Close();
response.Close();
}
By the way, the 0x599 or the 1433 port is usually used to connect to the MSSql server,
so you should use SqlConnection class to do it.
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C#